-
Notifications
You must be signed in to change notification settings - Fork 13k
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
ICE: index out of bounds in librustc_span/hygiene.rs possibly caused by LTO #71639
Comments
Minimal ExampleCargo.toml[package]
name = "asm_error"
version = "0.1.0"
edition = "2018"
# this causes a bug
[profile.release]
codegen-units = 1
lto = true lib.rs#![feature(llvm_asm)]
pub struct S;
pub fn f() {
unsafe { llvm_asm!( "call [rsi + 8*rax]" : : "rbx"(&S) : : "intel" ) };
} main.rsfn main() { asm_error::f() } @rustbot modify labels: -E-needs-mcve Compile with Backtrace:
|
In my effort to add this to the glacier, I found that I'm having trouble replicating this on the latest nightly. Has this been fixed on your end? |
Yes, I'm able to reproduce the ICE with the minimal example by steffahn.
|
Thanks! It turns out the problem was on my end, and now I'm able to get it to ICE. |
Clang apparently does not set an inline asm diagnostic handler when running in LTO mode. LLVM only allows us to attach a single integer to the However with LTO we don't have the span data for any dependencies, only the root crate, so this doesn't work. I think we should emulate clang's behavior and disable the inline asm diagnostic handler in LTO mode. |
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 | ^^^^^^^^^^^^^^^^^^^ ```
To reproduce
Run the following commands:
Meta
rustc --version --verbose
:Error output
Backtrace
Speculation
This could be related to LTO, because the bug was triggered when I added
to my
Cargo.toml
.The text was updated successfully, but these errors were encountered: