Skip to content

Commit 4e3b27e

Browse files
committed
C++: Add a testcase that needs indirect instruction/operand nodes.
1 parent d63b734 commit 4e3b27e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bool checkArgument(int* x);
2+
3+
void sink(int);
4+
5+
void testCheckArgument(int* p) {
6+
if (checkArgument(p)) {
7+
sink(*p); // $ barrier MISSING:barrier=1
8+
}
9+
}

cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.expected

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.new.DataFlow
3+
import semmle.code.cpp.controlflow.IRGuards
4+
import utils.test.InlineExpectationsTest
5+
6+
predicate instructionGuardChecks(IRGuardCondition gc, Instruction checked, boolean branch) {
7+
exists(CallInstruction call |
8+
call.getStaticCallTarget().hasName("checkArgument") and
9+
checked = call.getAnArgument() and
10+
gc.comparesEq(call.getAUse(), 0, false, any(BooleanValue bv | bv.getValue() = branch))
11+
)
12+
}
13+
14+
module BarrierGuard = DataFlow::InstructionBarrierGuard<instructionGuardChecks/3>;
15+
16+
predicate indirectBarrierGuard(DataFlow::Node node, int indirectionIndex) {
17+
node = BarrierGuard::getAnIndirectBarrierNode(indirectionIndex)
18+
}
19+
20+
predicate barrierGuard(DataFlow::Node node) { node = BarrierGuard::getABarrierNode() }
21+
22+
module Test implements TestSig {
23+
string getARelevantTag() { result = "barrier" }
24+
25+
predicate hasActualResult(Location location, string element, string tag, string value) {
26+
exists(DataFlow::Node node |
27+
barrierGuard(node) and
28+
value = ""
29+
or
30+
exists(int indirectionIndex |
31+
indirectBarrierGuard(node, indirectionIndex) and
32+
value = indirectionIndex.toString()
33+
)
34+
|
35+
tag = "barrier" and
36+
element = node.toString() and
37+
location = node.getLocation()
38+
)
39+
}
40+
}
41+
42+
import MakeTest<Test>

0 commit comments

Comments
 (0)