Skip to content

Commit f4eb5f5

Browse files
committed
C++: Convert 'getBranchSuccessor' to use abstract values.
1 parent b7292fb commit f4eb5f5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,21 @@ class IRGuardCondition extends Instruction {
359359
* return x;
360360
* ```
361361
*/
362-
private IRBlock getBranchSuccessor(boolean testIsTrue) {
362+
private IRBlock getBranchSuccessor(AbstractValue v) {
363363
branch.(ConditionalBranchInstruction).getCondition() = this and
364-
(
365-
testIsTrue = true and
364+
exists(BooleanValue bv | bv = v |
365+
bv.getValue() = true and
366366
result.getFirstInstruction() = branch.(ConditionalBranchInstruction).getTrueSuccessor()
367367
or
368-
testIsTrue = false and
368+
bv.getValue() = false and
369369
result.getFirstInstruction() = branch.(ConditionalBranchInstruction).getFalseSuccessor()
370370
)
371+
or
372+
exists(SwitchInstruction switch, CaseEdge kind | switch = branch |
373+
switch.getExpression() = this and
374+
result.getFirstInstruction() = switch.getSuccessor(kind) and
375+
kind = v.(MatchValue).getCase()
376+
)
371377
}
372378

373379
/** Holds if (determined by this guard) `left < right + k` evaluates to `isLessThan` if this expression evaluates to `testIsTrue`. */

0 commit comments

Comments
 (0)