Skip to content

Commit a4242bc

Browse files
authored
Merge pull request github#3962 from rdmarsh2/ir-barrierguard-checks-expr
C++: make IR BarrierGuard::checks match AST
2 parents 2e5af67 + 0bb6d0c commit a4242bc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,13 +699,20 @@ predicate localExprFlow(Expr e1, Expr e2) { localFlow(exprNode(e1), exprNode(e2)
699699
*/
700700
class BarrierGuard extends IRGuardCondition {
701701
/** Override this predicate to hold if this guard validates `instr` upon evaluating to `b`. */
702-
abstract predicate checks(Instruction instr, boolean b);
702+
predicate checksInstr(Instruction instr, boolean b) { none() }
703+
704+
/** Override this predicate to hold if this guard validates `expr` upon evaluating to `b`. */
705+
predicate checks(Expr e, boolean b) { none() }
703706

704707
/** Gets a node guarded by this guard. */
705708
final Node getAGuardedNode() {
706709
exists(ValueNumber value, boolean edge |
710+
(
711+
this.checksInstr(value.getAnInstruction(), edge)
712+
or
713+
this.checks(value.getAnInstruction().getConvertedResultExpression(), edge)
714+
) and
707715
result.asInstruction() = value.getAnInstruction() and
708-
this.checks(value.getAnInstruction(), edge) and
709716
this.controls(result.asInstruction().getBlock(), edge)
710717
)
711718
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/IRDataflowTestCommon.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import semmle.code.cpp.ir.IR
1010
class TestBarrierGuard extends DataFlow::BarrierGuard {
1111
TestBarrierGuard() { this.(CallInstruction).getStaticCallTarget().getName() = "guarded" }
1212

13-
override predicate checks(Instruction checked, boolean isTrue) {
13+
override predicate checksInstr(Instruction checked, boolean isTrue) {
1414
checked = this.(CallInstruction).getPositionalArgument(0) and
1515
isTrue = true
1616
}

0 commit comments

Comments
 (0)