Skip to content

Commit 43bbd4f

Browse files
committed
C++: Fix join order with 'pragma[noopt]'.
1 parent a8c57ec commit 43bbd4f

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/StackVariableReachability.qll

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,41 @@ abstract class StackVariableReachability extends string {
367367
)
368368
}
369369

370-
/** Holds if `cond` is a condition with a known truth value in `bb`. */
370+
/**
371+
* Holds if `cond` is a condition with a known truth value in `bb`.
372+
*
373+
* This predicate is `pragma[noopt]` as it seems difficult to get the correct join order for the
374+
* recursive case otherwise:
375+
* revBbSuccessorEntryReaches0(bb) -> getASuccessor -> prev_delta ->
376+
* revBbSuccessorEntryReaches0(pred) -> {isLoopCondition, isDisjunctionCondition, isLoopVariantCondition}
377+
*/
378+
pragma[noopt]
371379
private Condition getACondition(ControlFlowNode source, SemanticStackVariable v, BasicBlock bb) {
372-
revBbSuccessorEntryReaches0(source, pragma[only_bind_into](bb), v, _, this) and
380+
revBbSuccessorEntryReaches0(source, bb, v, _, this) and
373381
(
374382
result = getADirectCondition(bb) and
375383
(
376-
result.refutesCondition(getASinkCondition(v))
384+
exists(Condition c |
385+
c = getASinkCondition(v) and
386+
result.refutesCondition(c)
387+
)
377388
or
378-
result.impliesCondition(getABarrierCondition(v))
389+
exists(Condition c |
390+
c = getABarrierCondition(v) and
391+
result.impliesCondition(c)
392+
)
379393
)
380394
or
381395
exists(BasicBlock pred, LogicalCondition cond |
396+
pred.getASuccessor() = bb and
382397
cond = getACondition(source, v, pred) and
398+
revBbSuccessorEntryReaches0(source, pred, v, _, this) and
383399
result = cond and
384-
revBbSuccessorEntryReaches0(source, pragma[only_bind_into](pred), v, _, this) and
385-
pred.getASuccessor() = bb and
386-
not isLoopCondition(cond.getCondition(), pred, bb) and
387-
not isDisjunctionCondition(cond.getCondition(), pred, bb) and
388-
not isLoopVariantCondition(cond.getCondition(), pred, bb)
400+
exists(LogicalGuardCondition c | c = cond.getCondition() |
401+
not isLoopCondition(c, pred, bb) and
402+
not isDisjunctionCondition(c, pred, bb) and
403+
not isLoopVariantCondition(c, pred, bb)
404+
)
389405
)
390406
)
391407
}

0 commit comments

Comments
 (0)