-
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
Improve inline asm error diagnostics #72625
Conversation
I think we could get even better diagnostics if we could encode more data into the |
This comment has been minimized.
This comment has been minimized.
7302a02
to
bd7db0f
Compare
Would this fix #72664 ? |
Ah yes, indeed. |
This is a great improvement. |
📌 Commit bd7db0fb1ed741f8ef0342dd69797e4117af0f04 has been approved by |
--> $DIR/srcloc.rs:15:13 | ||
| | ||
LL | invalid_instruction | ||
| ^ |
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 would be nice if this could point at the entire width of invalid_instruction
. (I saw the FIXME
, which is why this isn't the case.)
note: instantiated into assembly here | ||
--> <inline asm>:3:13 | ||
| | ||
LL | invalid_instruction | ||
| ^^^^^^^^^^^^^^^^^^^ |
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 would be great if we could avoid the note
when it is redundant and the resulting evaluated assembly is the same as what is in the code.
@bors r=petrochenkov |
📌 Commit fc497f7 has been approved by |
Improve inline asm error diagnostics Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics. The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line `srcloc` attribute to map an error in inline assembly directly to the relevant line of source code. Incidentally also fixes rust-lang#71639 by disabling `srcloc` metadata during LTO builds since we don't know what crate it might have come from. We can only resolve `srcloc`s from the currently crate since it indexes into the source map for the current crate. Fixes rust-lang#72664 Fixes rust-lang#71639 r? @petrochenkov ### Old style ```rust #![feature(llvm_asm)] fn main() { unsafe { let _x: i32; llvm_asm!( "mov $0, $1 invalid_instruction $0, $1 mov $0, $1" : "=&r" (_x) : "r" (0) :: "intel" ); } } ``` ``` error: <inline asm>:3:14: error: invalid instruction mnemonic 'invalid_instruction' invalid_instruction ecx, eax ^~~~~~~~~~~~~~~~~~~ --> src/main.rs:6:9 | 6 | / llvm_asm!( 7 | | "mov $0, $1 8 | | invalid_instruction $0, $1 9 | | mov $0, $1" ... | 12 | | :: "intel" 13 | | ); | |__________^ ``` ### New style ```rust #![feature(asm)] fn main() { unsafe { asm!( "mov {0}, {1} invalid_instruction {0}, {1} mov {0}, {1}", out(reg) _, in(reg) 0i64, ); } } ``` ``` error: invalid instruction mnemonic 'invalid_instruction' --> test.rs:7:14 | 7 | invalid_instruction {0}, {1} | ^ | note: instantiated into assembly here --> <inline asm>:3:14 | 3 | invalid_instruction rax, rcx | ^^^^^^^^^^^^^^^^^^^ ```
Rollup of 13 pull requests Successful merges: - rust-lang#72543 (Account for missing lifetime in opaque and trait object return types) - rust-lang#72625 (Improve inline asm error diagnostics) - rust-lang#72637 (expand `env!` with def-site context) - rust-lang#72650 (Sort sidebar elements) - rust-lang#72657 (Allow types (with lifetimes/generics) in impl_lint_pass) - rust-lang#72666 (Add -Z profile-emit=<path> for Gcov gcda output.) - rust-lang#72668 (Fix missing parentheses Fn notation error) - rust-lang#72669 (rustc_session: Cleanup session creation) - rust-lang#72728 (Make bootstrap aware of relative libdir in stage0 compiler) - rust-lang#72757 (rustc_lexer: Optimize shebang detection slightly) - rust-lang#72772 (miri validation: clarify valid values of 'char') - rust-lang#72773 (Fix is_char_boundary documentation) - rust-lang#72777 (rustdoc: remove calls to `local_def_id_from_node_id`) Failed merges: r? @ghost
Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics.
The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line
srcloc
attribute to map an error in inline assembly directly to the relevant line of source code.Incidentally also fixes #71639 by disabling
srcloc
metadata during LTO builds since we don't know what crate it might have come from. We can only resolvesrcloc
s from the currently crate since it indexes into the source map for the current crate.Fixes #72664
Fixes #71639
r? @petrochenkov
Old style
New style