Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C++: Fix global variable dataflow FP#20040

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

MathiasVP
Copy link
Contributor

This PR fixes a very odd corner case of global dataflow through global variables.

Consider this snippet (which I've also added as a test):

int recursion = (sink(recursion), source());

The IR we generate for this snippet is roughly equivalent to:

void__initialize_recursion() {sink(recursion);  recursion =source();}

where__recursion represents the actual global variable. Since this is anIRFunction just like any otherFunction, it gets an initial SSA definition of the global variables that it reads, and it gets a final SSA use of the global variables that it defines. So for the point-of-view of dataflow the function ends up looking like:

void__initialize_recursion() {  recursion = __initialize_global;// (3)sink(recursion);// (4)  recursion =source();// (1)__final_use(recursion);// (2)}

where__initialize_global represents the initial SSA definition (aInitialGlobalValue node), and__final_use(recursion) represents the final SSA use (aFinalGlobalValue node).

And now global variable dataflow does its things and this happens:

  1. A write torecursion at// (1) flows to the final SSA use at// (2)
  2. A jump step causes flow from// (2) to the global dataflow node (aGlobalLikeVariableNode) forrecursion
  3. Another jump step from the global dataflow node forrecursion to the initial SSA definition forrecursion at// (3)
  4. A normal flow step from// (3) to the use at// (4).

But clearly we should not have flow in this case! So this PR fixes the FP by removing theInitialGlobalValue node for some global variablev at the entry for theIRFunction that initializesv.

I don't think this will ever happen on any real codebase. But since it was so easy to fix we might as well get this fix in 😄

@CopilotCopilotAI review requested due to automatic review settingsJuly 14, 2025 14:34
@MathiasVPMathiasVP requested a review froma team as acode ownerJuly 14, 2025 14:34
Copy link
Contributor

@CopilotCopilotAI left a 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 a false positive in global variable dataflow analysis for C++ code. The issue occurs in an edge case where a global variable is used within its own initialization expression, causing incorrect dataflow through SSA definitions.

  • Adds a test case demonstrating the problematic scenario with self-referential global variable initialization
  • Modifies the SSA internals to excludeInitialGlobalValue nodes fromIRFunctions that initialize the same global variable
  • Updates expected test results to reflect the new test case

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

FileDescription
test.cppAdds test case for self-referential global variable initialization
dataflow-consistency.expectedUpdates expected test results for the new test case
SsaInternals.qllImplements fix by filtering out problematic SSA definitions

@MathiasVPMathiasVP added the no-change-note-requiredThis PR does not need a change note labelJul 14, 2025
Copy link
Contributor

@jketemajketema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM if DCA is happy.

@jketemajketema merged commit2ed54d5 intogithub:mainJul 14, 2025
14 of 15 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@jketemajketemajketema approved these changes

Assignees
No one assigned
Labels
C++no-change-note-requiredThis PR does not need a change note
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@MathiasVP@jketema

[8]ページ先頭

©2009-2025 Movatter.jp