Skip to content

Commit 8c8b919

Browse files
committed
C++: Add an API for indirect barrier guards and use it in tests.
1 parent a6adf82 commit 8c8b919

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ signature predicate guardChecksSig(IRGuardCondition g, Expr e, boolean branch);
19031903
* in data flow and taint tracking.
19041904
*/
19051905
module BarrierGuard<guardChecksSig/3 guardChecks> {
1906-
/** Gets a node that is safely guarded by the given guard check. */
1906+
/** Gets an expression node that is safely guarded by the given guard check. */
19071907
ExprNode getABarrierNode() {
19081908
exists(IRGuardCondition g, Expr e, ValueNumber value, boolean edge |
19091909
e = value.getAnInstruction().getConvertedResultExpression() and
@@ -1912,6 +1912,16 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
19121912
g.controls(result.getBasicBlock(), edge)
19131913
)
19141914
}
1915+
1916+
/** Gets an indirect expression node that is safely guarded by the given guard check. */
1917+
IndirectExprNode getAnIndirectBarrierNode() {
1918+
exists(IRGuardCondition g, Expr e, ValueNumber value, boolean edge |
1919+
e = value.getAnInstruction().getConvertedResultExpression() and
1920+
result.getConvertedExpr(_) = e and
1921+
guardChecks(g, value.getAnInstruction().getConvertedResultExpression(), edge) and
1922+
g.controls(result.getBasicBlock(), edge)
1923+
)
1924+
}
19151925
}
19161926

19171927
/**

cpp/ql/test/library-tests/dataflow/dataflow-tests/BarrierGuard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ bool guarded(const int*);
7373
void bg_indirect_expr() {
7474
int *buf = indirect_source();
7575
if (guarded(buf)) {
76-
sink(buf); // $ SPURIOUS: ir
76+
sink(buf);
7777
}
7878
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ module IRTest {
9595
)
9696
or
9797
barrier = DataFlow::BarrierGuard<testBarrierGuard/3>::getABarrierNode()
98+
or
99+
barrier = DataFlow::BarrierGuard<testBarrierGuard/3>::getAnIndirectBarrierNode()
98100
}
99101
}
100102
}

0 commit comments

Comments
 (0)