Skip to content

Commit 48a3385

Browse files
committed
C++: Work around extractor issue CPP-383
This fixes `PointlessComparison.ql` on https://github.com/an-tao/drogon. The QL is a bit obfuscated because it looks for a pattern that's impossible according to the dbscheme. There is no accompanying test because we haven't been able to boil this problem down to a simple test case. If we could, we'd fix it directly in the extractor instead.
1 parent 3231b60 commit 48a3385

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/internal/ConstantExprs.qll

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,42 @@ predicate abortingFunction(Function f) {
1515
not potentiallyReturningFunction(f)
1616
}
1717

18+
/**
19+
* This relation is the same as the `el instanceof Function`, only obfuscated
20+
* so the optimizer will not understand that any `FunctionCall.getTarget()`
21+
* should be in this relation.
22+
*/
23+
pragma[noinline]
24+
private predicate isFunction(Element el) {
25+
el instanceof Function
26+
or
27+
el.(Expr).getParent() = el
28+
}
29+
30+
/**
31+
* Holds if `fc` is a `FunctionCall` with no return value for `getTarget`. This
32+
* can happen due to extractor issue CPP-383.
33+
*/
34+
pragma[noopt]
35+
private predicate callHasNoTarget(@funbindexpr fc) {
36+
exists(Function f |
37+
funbind(fc, f) and
38+
not isFunction(f)
39+
)
40+
}
41+
42+
// This base case is pulled out to work around QL-796
43+
private predicate potentiallyReturningFunctionCall_base(FunctionCall fc) {
44+
fc.isVirtual()
45+
or
46+
callHasNoTarget(fc)
47+
}
48+
1849
/** A function call that *may* return; if in doubt, we assume it may. */
1950
private predicate potentiallyReturningFunctionCall(FunctionCall fc) {
20-
potentiallyReturningFunction(fc.getTarget()) or fc.isVirtual()
51+
potentiallyReturningFunctionCall_base(fc)
52+
or
53+
potentiallyReturningFunction(fc.getTarget())
2154
}
2255

2356
/** A function that *may* return; if in doubt, we assume it may. */

0 commit comments

Comments
 (0)