Skip to content

Commit e079406

Browse files
authored
Merge pull request #1536 from jbj/leap-year-sameBaseType-perf
C++: Fix performance of leap year queries
2 parents 01ce344 + 2a6000c commit e079406

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ predicate setter(MemberVariable v, MemberFunction f, Class c) {
5353
v.getDeclaringType() = c and
5454
f.getName().matches("set%") and
5555
v.getAnAssignedValue().getEnclosingFunction() = f and
56-
not exists(MemberVariable v2 |
57-
v2.getDeclaringType() = c and
58-
v2.getAnAssignedValue().getEnclosingFunction() = f and
59-
v2 != v
56+
forall(MemberVariable v2 |
57+
v2.getAnAssignedValue().getEnclosingFunction() = f
58+
|
59+
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
/**
@@ -71,31 +71,11 @@ predicate getter(MemberVariable v, MemberFunction f, Class c) {
7171
v.getDeclaringType() = c and
7272
f.getName().matches("get%") and
7373
v.getAnAccess().getEnclosingFunction() = f and
74-
not exists(MemberVariable v2 |
75-
v2.getDeclaringType() = c and
76-
v2.getAnAccess().getEnclosingFunction() = f and
77-
v2 != v
74+
forall(MemberVariable v2 |
75+
v2.getAnAccess().getEnclosingFunction() = f
76+
|
77+
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)