Skip to content

Commit a825213

Browse files
committed
C++: Fix FP by not generating a global def entry node for variable 'v' in the 'IRfunction' for 'v' itself.
1 parent 46627c6 commit a825213

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ private predicate isGlobalDefImpl(
153153
GlobalLikeVariable v, IRFunction f, int indirection, int indirectionIndex
154154
) {
155155
exists(VariableAddressInstruction vai |
156+
// The right-hand side of an initialization of a global variable
157+
// creates its own `IRFunction`. We don't want flow into that `IRFunction`
158+
// since the variable is only initialized once.
159+
not vai.getEnclosingFunction() = v and
156160
vai.getEnclosingIRFunction() = f and
157161
vai.getAstVariable() = v and
158162
isUse(_, _, vai, indirection, indirectionIndex) and

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ irFlow
327327
| test.cpp:1117:27:1117:34 | call to source | test.cpp:1117:27:1117:34 | call to source |
328328
| test.cpp:1132:11:1132:16 | call to source | test.cpp:1121:8:1121:8 | x |
329329
| test.cpp:1138:17:1138:22 | call to source | test.cpp:1140:8:1140:18 | * ... |
330-
| test.cpp:1158:18:1158:42 | ... , ... | test.cpp:1158:23:1158:31 | recursion |
331330
| true_upon_entry.cpp:9:11:9:16 | call to source | true_upon_entry.cpp:13:8:13:8 | x |
332331
| true_upon_entry.cpp:17:11:17:16 | call to source | true_upon_entry.cpp:21:8:21:8 | x |
333332
| true_upon_entry.cpp:27:9:27:14 | call to source | true_upon_entry.cpp:29:8:29:8 | x |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,4 +1155,4 @@ namespace conflation_regression {
11551155
}
11561156
}
11571157

1158-
int recursion = (sink(recursion), source()); // $ SPURIOUS: ir
1158+
int recursion = (sink(recursion), source()); // clean

0 commit comments

Comments
 (0)