Skip to content

C++: Fix IR generation when ConditionDeclExpr does not have an immediate VariableAccess #15539

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

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Feb 7, 2024

The QLDoc for ConditionDeclExpr:

/**
 * Gets the compiler-generated variable access that conceptually occurs after
 * the initialization of the declared variable.
 */
VariableAccess getVariableAccess() { result = this.getChild(0) }

made it seem like the first child was always a compiler-generated variable access of the declared variable. However, the test added in the first commit (identified in #15506) shows that this is not always the case.

This PR adds another predicate to ConditionDeclExpr for getting the 0'th child without casting it to a VariableAccess. We then use this new predicate in IR generation instead of getVariableAccess, and this fixes the bug exposed by the first commit.

Commit-by-commit review encouraged.

@MathiasVP MathiasVP requested a review from a team as a code owner February 7, 2024 11:49
@github-actions github-actions bot added the C++ label Feb 7, 2024
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Feb 7, 2024
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Looks great, fixes a bunch of consistency failures.

@MathiasVP
Copy link
Contributor Author

Looks great, fixes a bunch of consistency failures.

Indeed! There are also some new results. Some of them are TPs and some of them are FPs. The FPs in particular are the three cpp/missing-check-scanf results on cmake-windows are FPs caused by guard conditions not being aware of switch statements.

I'll create an issue for this. I don't think this should block the PR.

@MathiasVP MathiasVP merged commit 0ee3c99 into github:main Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants