这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

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:

int global;

void set() {
  global = source();
}

void get() {
  sink(global);
}

we will generate a "final use" at the end of the set function (which represents the value of global as we're exiting the function), and an "initial definition" at the beginning of the get function (which represents the value of global 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:

  • The global variable is a struct and a function writes to one of its fields, or
  • The global variable is passed to a function which writes to the parameter.

For example, this now works:

int global;

void set_param(int* p) {
  *p = source();
}

void set_global() {
  set_param(&global); // this now generates a "final use of global" even though there's no `StoreInstruction` that writes to the address of `global`
}

void read_global() {
  sink(global);
}

DCA does show a slowdown on two projects: vim (which we've come to learn is infamous for their use of global variables), and php. 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 and php are clear outliers. QA showed no new timeouts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant