Skip to content
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 when creating ! instance via asm macro #87802

Closed
kangalio opened this issue Aug 5, 2021 · 3 comments · Fixed by #87985
Closed

ICE when creating ! instance via asm macro #87802

kangalio opened this issue Aug 5, 2021 · 3 comments · Fixed by #87985
Assignees
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kangalio
Copy link

kangalio commented Aug 5, 2021

Code

#![feature(asm)]

fn hmm() -> ! {
    let x;
    unsafe {
        asm!("/* {0} */", out(reg) x);
    }
    x
}

fn main() {
    hmm();
}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (25b764849 2021-08-04)
binary: rustc
commit-hash: 25b764849625cb090e8b81d12d2bb2295d073788
commit-date: 2021-08-04
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

error: internal compiler error: compiler/rustc_codegen_llvm/src/asm.rs:347:28: LLVM asm constraint validation failed
 --> src/main.rs:6:15
  |
6 |         asm!("/* {0} */", out(reg) x);
  |               ^^^^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/25b764849625cb090e8b81d12d2bb2295d073788/compiler/rustc_errors/src/lib.rs:980:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.56.0-nightly (25b764849 2021-08-04) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
Backtrace

   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::span_bug
   3: rustc_errors::Handler::span_bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::span_bug_fmt
   7: rustc_codegen_llvm::asm::<impl rustc_codegen_ssa::traits::asm::AsmBuilderMethods for rustc_codegen_llvm::builder::Builder>::codegen_inline_asm
   8: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_terminator
   9: rustc_codegen_ssa::mir::codegen_mir
  10: rustc_codegen_ssa::base::codegen_instance
  11: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  12: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  14: rustc_codegen_llvm::base::compile_codegen_unit
  15: rustc_codegen_ssa::base::codegen_crate
  16: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  17: rustc_interface::passes::QueryContext::enter
  18: rustc_interface::queries::Queries::ongoing_codegen
  19: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  20: rustc_span::with_source_map
  21: rustc_interface::interface::create_compiler_and_run
  22: scoped_tls::ScopedKey<T>::set

@kangalio kangalio added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 5, 2021
@jonas-schievink jonas-schievink added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) labels Aug 5, 2021
@kangalio
Copy link
Author

kangalio commented Aug 5, 2021

Somewhere during compilation of this code, LLVM's InlineAsm::Verify function returns false when checking "if the specified constraint string is legal for the type" (relevant rustc line).

Because of that, rustc_codegen_llvm::asm::inline_asm_call returns None, and the parent function then reports the bug.

@kangalio
Copy link
Author

kangalio commented Aug 6, 2021

I added a dbg! statement to log the function type and constraints string passed to LLVM:

[compiler/rustc_codegen_llvm/src/asm.rs:453] fty = { [0 x i8] } ()
[compiler/rustc_codegen_llvm/src/asm.rs:453] cons = "=&r,~{dirflag},~{fpsr},~{flags},~{memory}"

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Aug 12, 2021
@nbdd0121
Copy link
Contributor

@rustbot claim

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 15, 2021
Forbid `!` from being used in `asm!` output

Fixes rust-lang#87802

r? `@Amanieu`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Aug 15, 2021
Forbid `!` from being used in `asm!` output

Fixes rust-lang#87802

r? ``@Amanieu``
camsteffen added a commit to camsteffen/rust that referenced this issue Aug 15, 2021
Forbid `!` from being used in `asm!` output

Fixes rust-lang#87802

r? ```@Amanieu```
@bors bors closed this as completed in 896f058 Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants