C++: Global variable flow without explicit SSA definitions #15194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).It's kinda annoying that we have to put these syntactic restrictions (i.e., only put the "final use" into functions that actually write to the variable), but these are very much necessary for global variable flow to perform well.
This PR expands this syntactic list criteria we use to decide whether a "final use" of a global variable should be inserted at the end of a function. Specifically, we no longer just look for
StoreInstruction
s that target the global variable, but also look for places where the global variable is passed into a function. For example:and places where the global variable is a struct whose field is being written to by a function. For example: