-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Fix missing global variable flow #20126
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
Conversation
…ons that have a post-update node for the global variable.
849454c
to
163d4af
Compare
163d4af
to
fca49dd
Compare
What about the new alerts that DCA shows? |
I looked at about ~20 results (~10 struct S { int x, y; };
S s;
void set(int* x) {
*x = tainted_data();
}
void foo() {
set(&s.x);
}
void bar() {
int x = s.x;
// use x
} (of course behind numerous macro expansions because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes missing global variable flow cases by improving how the C++ data flow analysis tracks global variables. The implementation adds "final use" nodes when there are post-update nodes for global variables, covering scenarios where global variables are modified indirectly through function parameters or field assignments.
- Adds post-update node tracking for global variables modified through function calls or field updates
- Creates additional flow edges for global variables when they are modified indirectly
- Introduces new test cases to validate the improved global variable flow detection
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll | Extends global use detection to include post-update nodes |
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll | Refactors post-update node creation logic |
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll | Extracts post-update node predicate |
cpp/ql/test/library-tests/dataflow/fields/aliasing.cpp | Adds test cases for global field flow scenarios |
cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp | Adds test cases for globals without explicit definitions |
*.expected files | Updates expected test results with new flow edges |
This PR fixes a family of missing flow cases involving global variables.
First some background: We implement global variable flow by adding a "final use" at the exit of each function that writes to the global variable, and an "initial definition" at the entry of each function that reads the global variable. For example, for something like:
we will generate a "final use" at the end of the
set
function (which represents the value ofglobal
as we're exiting the function), and an "initial definition" at the beginning of theget
function (which represents the value ofglobal
as we're starting to execute the function).This PR also adds a "final use" of a global variable when there is a post-update node for the variable. This covers situations like:
struct
and a function writes to one of its fields, orFor example, this now works:
DCA does show a slowdown on two projects:
vim
(which we've come to learn is infamous for their use of global variables), andphp
. However, on average this is less than a 2.5% performance slowdown across all the projects.I also ran QA which also showed that
vim
andphp
are clear outliers. QA showed no new timeouts.