Skip to content

C++: Fix global flow without an SSA definition #12740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) {
Original file line number Diff line number Diff line change
@@ -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. |
17 changes: 17 additions & 0 deletions cpp/ql/test/library-tests/dataflow/dataflow-tests/globals.cpp
Original file line number Diff line number Diff line change
@@ -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
}
}