Skip to content

Commit c239e24

Browse files
committed
Add pragma to equal types to improve perf
1 parent 1e9c547 commit c239e24

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cpp/common/src/codingstandards/cpp/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ class VariableDeclarationEntryExternal extends VariableDeclarationEntry {
1919
VariableDeclarationEntryExternal() { this.getDeclaration() instanceof ExternalIdentifiers }
2020
}
2121

22+
predicate relevantPair(VariableDeclarationEntryExternal varA, VariableDeclarationEntryExternal varB) {
23+
not varA = varB and
24+
varA.getVariable().getName() = varB.getVariable().getName()
25+
}
26+
2227
predicate relevantTypes(Type a, Type b) {
2328
exists(VariableDeclarationEntryExternal varA, VariableDeclarationEntryExternal varB |
24-
not varA = varB and
25-
varA.getVariable().getName() = varB.getVariable().getName() and
29+
relevantPair(varA, varB) and
2630
a = varA.getType() and
2731
b = varB.getType()
2832
)
@@ -35,11 +39,10 @@ module IncompatibleObjectDeclaration<IncompatibleObjectDeclarationConfigSig Conf
3539
) {
3640
not isExcluded(decl1, Config::getQuery()) and
3741
not isExcluded(decl2, Config::getQuery()) and
42+
relevantPair(decl1, decl2) and
3843
not TypeEquivalence<TypesCompatibleConfig, relevantTypes/2>::equalTypes(decl1.getType(),
3944
decl2.getType()) and
40-
not decl1 = decl2 and
4145
decl1.getLocation().getStartLine() >= decl2.getLocation().getStartLine() and
42-
decl1.getVariable().getName() = decl2.getVariable().getName() and
4346
secondMessage = decl2.getName() and
4447
message = "The object is not compatible with a re-declaration $@."
4548
}

cpp/common/src/codingstandards/cpp/types/Compatible.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ module TypeEquivalence<TypeEquivalenceSig Config, interestedInEquality/2 interes
379379
* `interestedInNestedTypes` holds for the types, and holds if `t1` and `t2` are identical,
380380
* regardless of how `TypeEquivalenceSig` is defined.
381381
*/
382+
pragma[nomagic]
382383
predicate equalTypes(Type t1, Type t2) {
383384
interestedInNestedTypes(pragma[only_bind_into](t1), pragma[only_bind_into](t2)) and
384385
(

0 commit comments

Comments
 (0)