Skip to content

Commit 5ad0b39

Browse files
committed
C++: Fix performance of leap year queries
The `sameBaseType` predicate was fundamentally quadratic, and this blew up on large C++ code bases. Replacing it with calls to `Type.stripType` fixes performance and does not affect the qltests. It looks like `sameBaseType` was used purely an ad hoc heuristic, so I'm not worried about the slight semantic difference between `sameBaseType` and `stripType`.
1 parent a0dc840 commit 5ad0b39

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

cpp/ql/src/semmle/code/cpp/commons/StructLikeClass.qll

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ predicate setter(MemberVariable v, MemberFunction f, Class c) {
5959
v2 != v
6060
) and
6161
f.getNumberOfParameters() = 1 and
62-
sameBaseType(f.getParameter(0).getType(), v.getType())
62+
f.getParameter(0).getType().stripType() = v.getType().stripType()
6363
}
6464

6565
/**
@@ -77,25 +77,5 @@ predicate getter(MemberVariable v, MemberFunction f, Class c) {
7777
v2 != v
7878
) and
7979
f.getNumberOfParameters() = 0 and
80-
sameBaseType(f.getType(), v.getType())
81-
}
82-
83-
/**
84-
* Holds if `t1` and `t2` are the same type up to typedefs, specifiers,
85-
* and removing a single layer of pointers or references (but not arrays).
86-
* Equates, for example, `const int*` with `int`, but not `int**` with `int`
87-
* or `int[]` with `int`.
88-
*/
89-
predicate sameBaseType(Type t1, Type t2) {
90-
exists (Type base1, Type base2 |
91-
base1 = t1.getUnspecifiedType() and
92-
base2 = t2.getUnspecifiedType().getUnspecifiedType() and
93-
(
94-
base1 = base2 or
95-
base1.(PointerType).getBaseType() = base2 or
96-
base2.(PointerType).getBaseType() = base1 or
97-
base1.(ReferenceType).getBaseType() = base2 or
98-
base2.(ReferenceType).getBaseType() = base1
99-
)
100-
)
80+
f.getType().stripType() = v.getType().stripType()
10181
}

0 commit comments

Comments
 (0)