-
Notifications
You must be signed in to change notification settings - Fork 170
Test an escaped parameter read before its slot exists #339
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * A parameter whose address is taken only after an expression has read it is | ||
| * still in the register it arrived in, and its stack slot may not exist yet. | ||
| * Reloading it from that slot read whatever sat at offset zero of the frame. | ||
| * Keep the `&` after the arithmetic and the pointers in place: both are what | ||
| * make this path reachable. | ||
| */ | ||
|
|
||
| int sub_then_escape(int a, int b) | ||
| { | ||
| int x = a - b; | ||
| int *p = &b; | ||
| return x; | ||
| } | ||
|
|
||
| int add_then_escape(int a, int b) | ||
| { | ||
| int x = a + b; | ||
| int *p = &b; | ||
| return x; | ||
| } | ||
|
|
||
| int escape_first_operand(int a, int b) | ||
| { | ||
| int x = a - b; | ||
| int *p = &a; | ||
| return x; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| if (sub_then_escape(5, 2) != 3) | ||
| return 1; | ||
| if (add_then_escape(1, 2) != 3) | ||
| return 2; | ||
| if (escape_first_operand(5, 2) != 3) | ||
| return 3; | ||
| return 0; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file opens with an empty line where its sibling
tests/strength-reduce.copens with a comment naming the shape it guards. This test depends on a narrow shape (a parameter still sitting in its arrival register, its address taken only after the expression reads it), and nothing in the file says so. A later cleanup could drop the unusedpor move&babove the arithmetic, and the test would still pass while covering nothing. Move the explanation from the pull request description into the file:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied. The file has carried a header comment since the first push, but it explained why no store through the pointer is needed rather than warning against moving the
&or droppingp, which is the part a later cleanup would break — your wording covers that, so I took it as is.One deviation:
.ci/check-commentflow.shreflows the opening/*onto its own line, matchingtests/strength-reduce.c. The text is yours; the layout is commentflow's output.