Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import cpp
import codingstandards.c.cert
import codingstandards.cpp.MistypedFunctionArguments

from FunctionCall fc, Function f, Parameter p
from FunctionCall fc, Parameter p
where
not isExcluded(fc, ExpressionsPackage::doNotCallFunctionsWithIncompatibleArgumentsQuery()) and
p = fc.getTarget().getAParameter() and
(
mistypedFunctionArguments(fc, f, p)
mistypedFunctionArguments(fc, p)
or
complexArgumentPassedToRealParameter(fc, f, p)
complexArgumentPassedToRealParameter(fc, p)
)
select fc,
"Argument $@ in call to " + f.toString() + " is incompatible with parameter " + p.getTypedName() +
".", fc.getArgument(p.getIndex()) as arg, arg.toString()
"Argument $@ in " + fc.toString() + " is incompatible with parameter " + p.getTypedName() + ".",
fc.getArgument(p.getIndex()) as arg, arg.toString()
2 changes: 2 additions & 0 deletions change_notes/2026-08-28-improve-exp37-c-performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `EXP37-C` - `DoNotCallFunctionsWithIncompatibleArguments.ql`:
- Improved query evaluation performance. Query results are unchanged.
27 changes: 14 additions & 13 deletions cpp/common/src/codingstandards/cpp/MistypedFunctionArguments.qll
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ private predicate isTypeInComplexDomain(FloatingPointType type) {
type.getUnderlyingType().(FloatingPointType).getDomain() instanceof ComplexDomain
}

predicate mistypedFunctionArguments(FunctionCall fc, Function f, Parameter p) {
f = fc.getTarget() and
p = f.getAParameter() and
hasZeroParamDecl(f) and
isCompiledAsC(f.getFile()) and
not f.isVarargs() and
not f instanceof BuiltInFunction and
p.getIndex() < fc.getNumberOfArguments() and
// Parameter p and its corresponding call argument must have mismatched types
not argMayBeUsed(fc.getArgument(p.getIndex()), p)
predicate mistypedFunctionArguments(FunctionCall fc, Parameter p) {
Comment thread
mbaluda marked this conversation as resolved.
exists(Function f |
f = fc.getTarget() and
p = f.getAParameter() and
hasZeroParamDecl(f) and
isCompiledAsC(f.getFile()) and
not f.isVarargs() and
not f instanceof BuiltInFunction and
p.getIndex() < fc.getNumberOfArguments() and
// Parameter p and its corresponding call argument must have mismatched types
not argMayBeUsed(fc.getArgument(p.getIndex()), p)
)
}

predicate complexArgumentPassedToRealParameter(FunctionCall fc, Function f, Parameter p) {
f = fc.getTarget() and
p = f.getAParameter() and
predicate complexArgumentPassedToRealParameter(FunctionCall fc, Parameter p) {
p = fc.getTarget().getAParameter() and
// Some implementations implicitly convert complex floating point values by
// extracting the real part of the complex number (in-place or via a creal() call).
// This predicate holds in those cases unless the value is explicitly converted.
Expand Down
Loading