From 4ab01a265c13e24cd0b80575b94651476ff2fe42 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Fri, 28 Aug 2026 11:02:30 +0200 Subject: [PATCH 1/2] Refactor EXP37-C rule to simplify function argument checks and improve performance --- ...tCallFunctionsWithIncompatibleArguments.ql | 11 ++++---- .../cpp/MistypedFunctionArguments.qll | 27 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) 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/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. From 7878aa619eb62f4d10c8f1573d1885bf3c8b908a Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Fri, 28 Aug 2026 11:15:14 +0200 Subject: [PATCH 2/2] change note --- change_notes/2026-08-28-improve-exp37-c-performance.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 change_notes/2026-08-28-improve-exp37-c-performance.md 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