Skip to content

Commit 2b31928

Browse files
committed
C++: Add MaD barrier guard tests.
1 parent dc7ce3f commit 2b31928

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,39 @@ void testCheckArgument(int p) {
1212
if (checkArgument(&p)) {
1313
sink(p); // $ barrier=glval<int> indirect_barrier=int
1414
}
15+
}
16+
17+
int* get_clean_value(int* x) { return x; }
18+
bool is_clean_value(int*);
19+
20+
int* get_clean_pointer(int* x) { return x; }
21+
bool is_clean_pointer(int*);
22+
23+
void sink(int);
24+
void sink(int*);
25+
26+
void test_mad(int x, int* p) {
27+
{
28+
if(is_clean_value(&x)) {
29+
sink(x); // $ MISSING: external=int
30+
}
31+
}
32+
33+
{
34+
if(is_clean_value(p)) {
35+
sink(*p); // $ MISSING: external=int
36+
}
37+
}
38+
39+
{
40+
if(is_clean_pointer(p)) {
41+
sink(p); // $ MISSING: external=int*
42+
}
43+
}
44+
45+
{
46+
if(is_clean_pointer(&x)) {
47+
sink(x); // $ MISSING: external=glval<int>
48+
}
49+
}
1550
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: barrierModel
5+
data:
6+
- ["", "", False, "get_clean_pointer", "", "", "ReturnValue", "test-barrier", "manual"]
7+
- ["", "", False, "get_clean_data", "", "", "ReturnValue[*]", "test-barrier", "manual"]
8+
- addsTo:
9+
pack: codeql/cpp-all
10+
extensible: barrierGuardModel
11+
data:
12+
- ["", "", False, "is_clean_value", "", "", "Argument[*0]", "true", "test-barrier", "manual"]
13+
- ["", "", False, "is_clean_pointer", "", "", "Argument[0]", "true", "test-barrier", "manual"]

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import cpp
22
import semmle.code.cpp.dataflow.new.DataFlow
33
import semmle.code.cpp.controlflow.IRGuards
44
import utils.test.InlineExpectationsTest
5+
import semmle.code.cpp.dataflow.ExternalFlow
56

67
predicate instructionGuardChecks(IRGuardCondition gc, Instruction checked, boolean branch) {
78
exists(CallInstruction call |
@@ -31,13 +32,11 @@ module Test implements TestSig {
3132
string getARelevantTag() { result = ["barrier", "indirect_barrier"] }
3233

3334
predicate hasActualResult(Location location, string element, string tag, string value) {
34-
exists(DataFlow::Node node, string s |
35-
indirectBarrierGuard(node, s) and
36-
value = s and
35+
exists(DataFlow::Node node |
36+
indirectBarrierGuard(node, value) and
3737
tag = "indirect_barrier"
3838
or
39-
barrierGuard(node, s) and
40-
value = s and
39+
barrierGuard(node, value) and
4140
tag = "barrier"
4241
|
4342
element = node.toString() and

0 commit comments

Comments
 (0)