diff --git a/c/cert/src/rules/EXP37-C/DoNotCallFunctionsWithIncompatibleArguments.ql b/c/cert/src/rules/EXP37-C/DoNotCallFunctionsWithIncompatibleArguments.ql index 4c5ba57504..38e5ab8934 100644 --- a/c/cert/src/rules/EXP37-C/DoNotCallFunctionsWithIncompatibleArguments.ql +++ b/c/cert/src/rules/EXP37-C/DoNotCallFunctionsWithIncompatibleArguments.ql @@ -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() diff --git a/change_notes/2026-08-28-improve-exp37-c-performance.md b/change_notes/2026-08-28-improve-exp37-c-performance.md new file mode 100644 index 0000000000..65baded760 --- /dev/null +++ b/change_notes/2026-08-28-improve-exp37-c-performance.md @@ -0,0 +1,2 @@ +- `EXP37-C` - `DoNotCallFunctionsWithIncompatibleArguments.ql`: + - Improved query evaluation performance. Query results are unchanged. \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/MistypedFunctionArguments.qll b/cpp/common/src/codingstandards/cpp/MistypedFunctionArguments.qll index 6fe90372da..ecb4569a0f 100644 --- a/cpp/common/src/codingstandards/cpp/MistypedFunctionArguments.qll +++ b/cpp/common/src/codingstandards/cpp/MistypedFunctionArguments.qll @@ -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) { + 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.