-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Mark inout asm! operands as used in liveness pass #77976
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthewjasper (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
#![deny(unused_variables)] | ||
|
||
// Tests the single variable inout case | ||
unsafe fn rep_movsb(mut dest: *mut u8, mut src: *const u8, mut n: usize) -> *mut u8 { |
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.
Can you also add a test that ensures projections work correctly as well?
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.
Added a couple of test cases for field projection, thanks!
@@ -0,0 +1,36 @@ | |||
// Ensure inout asm! operands are marked as used by the liveness pass | |||
|
|||
// only-x86_64 |
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.
This test could also be made architecture independent by doing something like this:
unsafe fn rep_movsb(mut src: *const u8) {
asm!("/*{0}*/", inout(reg) src);
}
It would allow testing this by people who use something else than x86_64 as a host.
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.
Fixed in the latest changes, thanks!
@@ -1199,7 +1199,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { | |||
} | |||
} | |||
hir::InlineAsmOperand::InOut { expr, .. } => { | |||
succ = self.propagate_through_place_components(expr, succ); | |||
succ = self.propagate_through_expr(expr, succ); |
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.
I didn't dig too deep into this, but looking at Assign
code as an example, I suspect this may need both propagate_through_place_components
and propagate_through_expr
.
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.
It looks like it was determined that propagate_through_place_components
would be the necessary call here in order to avoid improperly setting the inout expr as its own successor/predecessory.
@bors r+ |
📌 Commit 8f0bced has been approved by |
…hewjasper Mark inout asm! operands as used in liveness pass Variables used in `inout` operands in inline assembly (that is, they're used as both input and output to some arbitrary assembly instruction) are being marked as read and written, but are not marked as being used in the RWU table during the liveness pass. This can result in such expressions triggering an unused variable lint warning. This is incorrect behavior- reads without uses are currently only used for compound assignments. We conservatively assume that an `inout` operand is being read and used in the context of the assembly instruction. Closes rust-lang#77915
Failed in https://github.com/rust-lang-ci/rust/runs/1284758758:
The test needs a tweak. |
@JohnTitor Sorry to break the rollup- changed it back to only target x86_64, like other inline asm tests in ui. Confirmed test is properly ignored on other platforms. |
@oliviacrain No worries! You should also bless the output as the line number is changed. |
@JohnTitor Thanks for catching that! Output blessed. |
Thanks! |
📌 Commit dc29c7a has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#77420 (Unify const-checking structured errors for `&mut` and `&raw mut`) - rust-lang#77554 (Support signed integers and `char` in v0 mangling) - rust-lang#77976 (Mark inout asm! operands as used in liveness pass) - rust-lang#78009 (Haiku: explicitly set CMAKE_SYSTEM_NAME when cross-compiling) - rust-lang#78084 (Greatly improve display for small mobile devices screens) - rust-lang#78155 (Fix two small issues in compiler/rustc_lint/src/types.rs) - rust-lang#78156 (Fixed build failure of `rustfmt`) - rust-lang#78172 (Add test case for rust-lang#77062) - rust-lang#78188 (Add tracking issue number for pin_static_ref) - rust-lang#78200 (Add `ControlFlow::is_{break,continue}` methods) Failed merges: r? `@ghost`
Variables used in
inout
operands in inline assembly (that is, they're used as both input and output to some arbitrary assembly instruction) are being marked as read and written, but are not marked as being used in the RWU table during the liveness pass. This can result in such expressions triggering an unused variable lint warning. This is incorrect behavior- reads without uses are currently only used for compound assignments. We conservatively assume that aninout
operand is being read and used in the context of the assembly instruction.Closes #77915