diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll index 0cd152e24732..78a50d18da56 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll @@ -155,11 +155,13 @@ private newtype TDefOrUseImpl = TGlobalUse(GlobalLikeVariable v, IRFunction f, int indirectionIndex) { // Represents a final "use" of a global variable to ensure that // the assignment to a global variable isn't ruled out as dead. - exists(VariableAddressInstruction vai, int defIndex | + exists(VariableAddressInstruction vai, int i | vai.getEnclosingIRFunction() = f and vai.getAstVariable() = v and - isDef(_, _, _, vai, _, defIndex) and - indirectionIndex = [0 .. defIndex] + 1 + indirectionIndex = [0 .. i] + 1 + | + isDef(_, _, _, vai, indirectionIndex, i) or + isUse(_, _, vai, indirectionIndex, i) ) } or TGlobalDefImpl(GlobalLikeVariable v, IRFunction f, int indirectionIndex) { diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected b/cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected index eb9e8efb1d2d..551d248aa683 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected @@ -44,6 +44,7 @@ postWithInFlow | example.c:28:23:28:25 | pos [inner post update] | PostUpdateNode should not be the target of local flow. | | globals.cpp:13:5:13:19 | flowTestGlobal1 [post update] | PostUpdateNode should not be the target of local flow. | | globals.cpp:23:5:23:19 | flowTestGlobal2 [post update] | PostUpdateNode should not be the target of local flow. | +| globals.cpp:34:18:34:18 | x [post update] | PostUpdateNode should not be the target of local flow. | | lambdas.cpp:23:3:23:14 | v [post update] | PostUpdateNode should not be the target of local flow. | | lambdas.cpp:43:3:43:3 | c [post update] | PostUpdateNode should not be the target of local flow. | | ref.cpp:11:5:11:7 | lhs [post update] | PostUpdateNode should not be the target of local flow. | diff --git a/cpp/ql/test/library-tests/dataflow/dataflow-tests/globals.cpp b/cpp/ql/test/library-tests/dataflow/dataflow-tests/globals.cpp index cdfd2e04f928..e317c4dfef15 100644 --- a/cpp/ql/test/library-tests/dataflow/dataflow-tests/globals.cpp +++ b/cpp/ql/test/library-tests/dataflow/dataflow-tests/globals.cpp @@ -22,3 +22,20 @@ void readGlobal2() { void writeGlobal2() { flowTestGlobal2 = source(); } + +namespace MyNamespace { + struct A { + int x; + }; + + A global_a; + + void set_without_ssa_def() { + global_a.x = source(); + } + + void call_set_without_ssa_def() { + set_without_ssa_def(); + sink(global_a.x); // $ ir MISSING: ast + } +} \ No newline at end of file