Skip to content

Commit 8aeb9b9

Browse files
authored
Merge pull request #14219 from MathiasVP/fix-phi-flow-2
C++: Fix `phi`->`phi` flow
2 parents ff7ff6d + b0566af commit 8aeb9b9

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ predicate fromPhiNode(SsaPhiNode nodeFrom, Node nodeTo) {
766766
or
767767
exists(PhiNode phiTo |
768768
phi != phiTo and
769-
lastRefRedefExt(phi, _, _, phiTo) and
769+
lastRefRedefExt(phi, bb1, i1, phiTo) and
770770
nodeTo.(SsaPhiNode).getPhiNode() = phiTo
771771
)
772772
)
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); // clean
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)