Skip to content

Commit 7f26f07

Browse files
committed
C++: Fix isFromMacroDefinition join order
This fixes the performance of `SignedOverflowCheck.ql` on jluttine/suitesparse.
1 parent 82499b0 commit 7f26f07

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,22 @@ predicate functionContainsPreprocCode(Function f) {
9494
* ```
9595
*/
9696
predicate isFromMacroDefinition(Element e) {
97-
exists(MacroInvocation mi |
97+
exists(MacroInvocation mi, Location eLocation, Location miLocation |
9898
// e is in mi
9999
mi.getAnExpandedElement() = e and
100100
// and e was apparently not passed in as a macro parameter
101-
e.getLocation().getStartLine() = mi.getLocation().getStartLine() and
102-
e.getLocation().getStartColumn() = mi.getLocation().getStartColumn()
101+
eLocation = e.getLocation() and
102+
miLocation = mi.getLocation() and
103+
nonBindingIntEquality(eLocation.getStartLine(), miLocation.getStartLine()) and
104+
nonBindingIntEquality(eLocation.getStartColumn(), miLocation.getStartColumn())
103105
)
104106
}
107+
108+
/**
109+
* Holds if `x = y` but gets compiled to a filter instead of a join. This can
110+
* be used to avoid bad join orders where integers are joined too early.
111+
*/
112+
bindingset[x, y]
113+
private predicate nonBindingIntEquality(int x, int y) {
114+
x >= y and y >= x
115+
}

0 commit comments

Comments
 (0)