-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustc's analyses have different order of eval for asm!
than what trans emits.
#14962
Comments
…puts. Fix rust-lang#14962. Also reordered the fields in libsyntax to reflect the order that the expressions occur in an instance of `asm!`, as an attempt to remind others of this ordering. Finally, added a couple notes about cases that may need to be further revised when/if rust-lang#14936 is addressed.
I think this has just worked out? A small diff: #[cfg(any(not(target_arch = "x86"), not(target_arch = "x86_64")))]
pub fn main() {} transcript: steve@warmachine:~/tmp$ rustc asm-flow.rs --cfg overwrite_in_both_with_liveness && ./asm-flow
asm-flow.rs:6:10: 6:25 warning: unknown lint: `dead_assignment`, #[warn(unknown_lints)] on by default
asm-flow.rs:6 #![allow(dead_assignment)]
^~~~~~~~~~~~~~~
steve@warmachine:~/tmp$ rustc asm-flow.rs --cfg augment_in_input && ./asm-flow
asm-flow.rs:6:10: 6:25 warning: unknown lint: `dead_assignment`, #[warn(unknown_lints)] on by default
asm-flow.rs:6 #![allow(dead_assignment)]
^~~~~~~~~~~~~~~
steve@warmachine:~/tmp$ rustc asm-flow.rs --cfg augment_in_output && ./asm-flow
asm-flow.rs:6:10: 6:25 warning: unknown lint: `dead_assignment`, #[warn(unknown_lints)] on by default
asm-flow.rs:6 #![allow(dead_assignment)]
^~~~~~~~~~~~~~~ |
I'm seeing the following. All (compilable) asserts pass. The unused_assignments lint appears incorrect though. I've included some annotated code samples below drawn from the original issue which still represent incorrect behavior. Those that appear to have been fixed are no longer included. As far as I can tell, we do now correctly detect when reading undefined memory -- so there has been progress. I'm uncertain if we've regressed since @steveklabnik's example above, but it does look like it... #![feature(asm)]
fn main() {
let mut x: isize = 0;
let y: isize = 1;
let mut z: isize;
unsafe {
asm!("mov ($1), $0"
: "=r"(*{z=2; &mut x})
: "r"(&{z=3; y}));
// ^ value assigned to `z` is never read -- this is wrong
}
assert_eq!(z, 3); // Passes
} #![feature(asm)]
fn main() {
let mut x: isize = 0;
let y: isize = 1;
let mut z: isize;
unsafe {
asm!("mov ($1), $0"
: "=r"(*{z=2; &mut x})
: "r"(&{z+=3; y}));
// ^ value assigned is never read -- wrong
}
assert_eq!(z, 5); // Passes
} |
Yes it looks like the main item remaining here is the incorrect control flow model of the |
This is fixed with the new |
The double warning is fixed by #72537, so I'm going to close this issue. |
The main work items remaining here is the incorrect linting of the following example (play):
I probably should make sure that the other examples have been turned into tests.
Original bug report follows
While making test cases for #14873 and investigating how rustc currently models the control flow of
asm!
(and eventually filing #14936), I discovered something peculiar: trans emits code that evaluates the output expressions first, and then the input expressions (as illustrated in the test case for=r
on #14936), but every rustc analysis that I looked at (liveness
,expr_use_visitor
, etc) treatsasm!
as if the input expressions are evaluated first, and then the output expressions.Here is an illustrative test case: with some comments to try to clarify what is happening in the various cases
Transcript of various runs on above code:
Notes on the above transcript:
trans
: we evaluate output expressions first, then input expressions. Thus theassert_eq
inoverwrite_in_both
passesz=3
is unused, even though it is the other assignmentz=2
that should be flagged as a dead_assignment.println!("z: {}, z)
; but it is not printingz: 3
as the compiler might think it should; it is instead printingz: 0
)&int
before it has been initialized.The text was updated successfully, but these errors were encountered: