Skip to content

Commit 2a55034

Browse files
committed
C++: Add failing test.
1 parent b9acf1a commit 2a55034

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int source();
2+
void gard_condition_sink(int);
3+
void use(int);
4+
/*
5+
This test checks that we hit the node corresponding to the expression node that wraps `source`
6+
in the condition `source >= 0`.
7+
*/
8+
void test_guard_condition(int source, bool b)
9+
{
10+
if (b) {
11+
use(source);
12+
}
13+
14+
if (source >= 0) {
15+
use(source);
16+
}
17+
18+
gard_condition_sink(source); // $ SPURIOUS: guard-condition-regression
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
testFailures
2+
failures
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import TestUtilities.InlineExpectationsTest
2+
private import cpp
3+
private import semmle.code.cpp.ir.dataflow.DataFlow
4+
private import semmle.code.cpp.controlflow.IRGuards
5+
6+
module IRTestAllocationConfig implements DataFlow::ConfigSig {
7+
predicate isSource(DataFlow::Node source) {
8+
source.asParameter().getName().matches("source%") and
9+
source.getLocation().getFile().getBaseName() = "guard-condition-regression-test.cpp"
10+
}
11+
12+
predicate isSink(DataFlow::Node sink) {
13+
exists(FunctionCall call, Expr e | e = call.getAnArgument() |
14+
call.getTarget().getName() = "gard_condition_sink" and
15+
sink.asExpr() = e
16+
)
17+
}
18+
19+
predicate isBarrier(DataFlow::Node node) {
20+
exists(GuardCondition gc | node.asExpr() = gc.getAChild*())
21+
}
22+
}
23+
24+
private module Flow = DataFlow::Global<IRTestAllocationConfig>;
25+
26+
module GuardConditionRegressionTest implements TestSig {
27+
string getARelevantTag() { result = "guard-condition-regression" }
28+
29+
predicate hasActualResult(Location location, string element, string tag, string value) {
30+
exists(DataFlow::Node sink |
31+
Flow::flowTo(sink) and
32+
location = sink.getLocation() and
33+
element = sink.toString() and
34+
tag = "guard-condition-regression" and
35+
value = ""
36+
)
37+
}
38+
}
39+
40+
import MakeTest<GuardConditionRegressionTest>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ WARNING: Module DataFlow has been deprecated and may be removed in future (test.
55
WARNING: Module DataFlow has been deprecated and may be removed in future (test.ql:40,25-33)
66
WARNING: Module DataFlow has been deprecated and may be removed in future (test.ql:42,17-25)
77
WARNING: Module DataFlow has been deprecated and may be removed in future (test.ql:46,20-28)
8-
failures
98
testFailures
9+
failures

0 commit comments

Comments
 (0)