Skip to content

C++: Flow out of invalid functions#12005

Merged
MathiasVP merged 2 commits intogithub:mathiasvp/replace-ast-with-ir-use-usedataflowfrom
MathiasVP:flow-out-of-invalid-functions
Jan 29, 2023
Merged

C++: Flow out of invalid functions#12005
MathiasVP merged 2 commits intogithub:mathiasvp/replace-ast-with-ir-use-usedataflowfrom
MathiasVP:flow-out-of-invalid-functions

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

We were not getting flow out of functions that were missing return statements since they might not have a ReturnInstruction.

After this PR, we (ab)use the generated UnreachedInstruction to assign an index in the final basic block so that SSA will ensure that we have flow out of the (invalid) function.

@MathiasVP MathiasVP requested a review from a team as a code owner January 27, 2023 11:47
@github-actions github-actions Bot added the C++ label Jan 27, 2023
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jan 27, 2023
return instanceof ReturnInstruction or
return instanceof UnreachedInstruction
|
block.getInstruction(index) = return and
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

index + 1 has been replaced here by index. Was this incorrect before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, good question. It wasn't actually incorrect. The only thing we require is that it's the last use of the parameter in the body of the function. ssa0/SsaInternals.qll did index + 1, and SsaInternals.qll did index. So I just synced them up to be index for consistency. This will hopefully make it easier to merge those two files into one parameterized module eventually.

Copy link
Copy Markdown
Contributor Author

@MathiasVP MathiasVP Jan 27, 2023

Choose a reason for hiding this comment

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

index + 1 might actually be problematic since we can generate IR where the UnreachedInstruction is the only thing in the block. So there wouldn't necessarily be any instruction at block.getInstruction(index + 1).

This is different from ReturnInstructions since we know there is always a ExitFunctionInstruction (or whatever it's called) after the ReturnInstructions.

Copy link
Copy Markdown
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

LGTM provided DCA is happy and we now have the two missing results back in our internal tests.

@MathiasVP
Copy link
Copy Markdown
Contributor Author

The internal test still isn't recovered, but I think there's an additional step necessary for this. I'll write up my investigation in our internal issue for this.

@MathiasVP MathiasVP merged commit 9573395 into github:mathiasvp/replace-ast-with-ir-use-usedataflow Jan 29, 2023
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