Skip to content

Commit 84a0ed5

Browse files
authored
Merge pull request #933 from github/michaelrfairhurst/performance-fixes-upgrading-to-2.20.7
Fix bad joins on function names and unnecessarily large relation on integer constant macros
2 parents b993d89 + a9c412d commit 84a0ed5

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,32 @@ import codingstandards.c.cert
2424
import codingstandards.cpp.types.Compatible
2525
import ExternalIdentifiers
2626

27-
predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
27+
predicate interestedInFunctions(
28+
FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, ExternalIdentifiers d
29+
) {
2830
not f1 = f2 and
29-
f1.getDeclaration() = f2.getDeclaration() and
30-
f1.getName() = f2.getName()
31+
d = f1.getDeclaration() and
32+
d = f2.getDeclaration()
33+
}
34+
35+
predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
36+
interestedInFunctions(f1, f2, _)
3137
}
3238

39+
module FuncDeclEquiv =
40+
FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>;
41+
3342
from ExternalIdentifiers d, FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
3443
where
3544
not isExcluded(f1, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
3645
not isExcluded(f2, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
37-
not f1 = f2 and
38-
f1.getDeclaration() = d and
39-
f2.getDeclaration() = d and
40-
f1.getName() = f2.getName() and
46+
interestedInFunctions(f1, f2, d) and
4147
(
4248
//return type check
43-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalReturnTypes(f1,
44-
f2)
49+
not FuncDeclEquiv::equalReturnTypes(f1, f2)
4550
or
4651
//parameter type check
47-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalParameterTypes(f1,
48-
f2)
52+
not FuncDeclEquiv::equalParameterTypes(f1, f2)
4953
) and
5054
// Apply ordering on start line, trying to avoid the optimiser applying this join too early
5155
// in the pipeline

c/misra/src/rules/RULE-7-5/IncorrectlySizedIntegerConstantMacroArgument.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ predicate matchesSign(IntegerConstantMacro macro, PossiblyNegativeLiteral litera
2020
literal.isNegative() implies macro.isSigned()
2121
}
2222

23+
bindingset[literal]
2324
predicate matchesSize(IntegerConstantMacro macro, PossiblyNegativeLiteral literal) {
2425
literal.getRawValue() <= macro.maxValue() and
2526
literal.getRawValue() >= macro.minValue()

c/misra/src/rules/RULE-8-4/CompatibleDeclarationFunctionDefined.ql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclaration
2323
f1.getDeclaration() instanceof ExternalIdentifiers and
2424
f1.isDefinition() and
2525
f1.getDeclaration() = f2.getDeclaration() and
26-
// This condition should always hold, but removing it affects join order performance.
27-
f1.getName() = f2.getName() and
2826
not f2.isDefinition() and
2927
not f1.isFromTemplateInstantiation(_) and
3028
not f2.isFromTemplateInstantiation(_)
3129
}
3230

31+
module FunDeclEquiv =
32+
FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>;
33+
3334
from FunctionDeclarationEntry f1
3435
where
3536
not isExcluded(f1, Declarations4Package::compatibleDeclarationFunctionDefinedQuery()) and
@@ -44,17 +45,13 @@ where
4445
or
4546
//or one exists that is close but incompatible in some way
4647
exists(FunctionDeclarationEntry f2 |
47-
f1.getName() = f2.getName() and
48-
not f2.isDefinition() and
49-
f2.getDeclaration() = f1.getDeclaration() and
48+
interestedInFunctions(f1, f2) and
5049
(
5150
//return types differ
52-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalReturnTypes(f1,
53-
f2)
51+
not FunDeclEquiv::equalReturnTypes(f1, f2)
5452
or
5553
//parameter types differ
56-
not FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>::equalParameterTypes(f1,
57-
f2)
54+
not FunDeclEquiv::equalParameterTypes(f1, f2)
5855
or
5956
//parameter names differ
6057
parameterNamesUnmatched(f1, f2)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `DCL40-C`, `RULE-8-4`: `IncompatibleFunctionDeclarations.ql`, `CompatibleDeclarationFunctionDefined.ql`.
2+
- Fixed performance issues introduced when upgrading to CodeQL `2.20.7` by removing unnecessary check that matching function declarations have matching names.
3+
- `RULE-7-5`: `IncorrectlySizedIntegerConstantMacroArgument.ql`.
4+
- Added a `bindingset` to improve performance when checking if a literal matches the size of an integer constant macro.

0 commit comments

Comments
 (0)