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

Compiler panic when attempting to use non immediate as assembly parameter #54067

Closed
crawford opened this issue Sep 8, 2018 · 2 comments · Fixed by #71182
Closed

Compiler panic when attempting to use non immediate as assembly parameter #54067

crawford opened this issue Sep 8, 2018 · 2 comments · Fixed by #71182
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crawford
Copy link

crawford commented Sep 8, 2018

Take the following code:

#![feature(asm)]

pub fn boot(addr: Option<u32>) {
    unsafe {
        asm!(
            "mov sp, $0"
             :
             : "r" (addr)
        );
    }
}

Attempting to compile this results in the following:

$ cargo build
   Compiling ice v0.1.0 (file:///home/alex/code/ice)                                                                                                                                           
error: internal compiler error: librustc_codegen_llvm/mir/operand.rs:145: not immediate: OperandRef(Pair((i32:  %7 = load i32, i32* %6, align 4, !dbg !29, !range !31), (i32:  %9 = load i32, i32* %8, align 4, !dbg !29)) @ TyLayout { ty: std::option::Option<u32>, details: LayoutDetails { variants: Tagged { tag: Scalar { value: Int(I32, false), valid_range: 0..=1 }, variants: [LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [], memory_index: [] }, abi: Aggregate { sized: true }, align: Align { abi_pow2: 0, pref_pow2: 3 }, size: Size { raw: 4 } }, LayoutDetails { variants: Single { index: 1 }, fields: Arbitrary { offsets: [Size { raw: 4 }], memory_index: [0] }, abi: Aggregate { sized: true }, align: Align { abi_pow2: 2, pref_pow2: 3 }, size: Size { raw: 8 } }] }, fields: Arbitrary { offsets: [Size { raw: 0 }], memory_index: [0] }, abi: ScalarPair(Scalar { value: Int(I32, false), valid_range: 0..=1 }, Scalar { value: Int(I32, false), valid_range: 0..=4294967295 }), align: Align { abi_pow2: 2, pref_pow2: 3 }, size: Size { raw: 8 } } })

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:587:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error


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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.30.0-nightly (fc81e3624 2018-09-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `ice`.

I think the compiler should fail with something along the lines of "you attempted to use a complex type (Option<u32>) where I expected an immediate".

@nagisa nagisa added A-inline-assembly Area: Inline assembly (`asm!(…)`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Sep 9, 2018
@alexandermerritt
Copy link
Contributor

alexandermerritt commented Sep 25, 2018

edit: not sure if these symptoms are the same, but here's what I stumbled across.

The following code generates a similar result for me:

// ice.rs
#![feature(asm)]
pub struct Foo {
    pub x: usize,
    pub y: usize
}
#[no_mangle]
pub unsafe fn ice() -> () {
    let bar: Foo = Foo { x: 0, y: 0 };
    asm!("lgdt %0" : : "m" (bar) : : );
}
fn main() { }
// EOF

The no_mangle and struct Foo seem to be required, else the ICE is not triggered.

Output

% rustc ice.rs
error: internal compiler error: librustc_codegen_llvm/mir/operand.rs:144: not immediate: OperandRef(Pair((i64:  %5 = load i64, i64* %4, align 8), (i64:  %7 = load i64, i64* %6, align 8)) @ TyLayout { ty: Foo, details: LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 8 }], memory_index: [0, 1] }, abi: ScalarPair(Scalar { value: Int(I64, false), valid_range: 0..=18446744073709551615 }, Scalar { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), align: Align { abi_pow2: 3, pref_pow2: 3 }, size: Size { raw: 16 } } })

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:587:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:481
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  15: rustc_codegen_llvm::mir::codegen_mir
  16: rustc_codegen_llvm::base::codegen_instance
  17: rustc_codegen_llvm::mono_item::MonoItemExt::define
  18: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  19: rustc::dep_graph::graph::DepGraph::with_task
  20: rustc_codegen_llvm::base::codegen_crate
  21: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  22: rustc::util::common::time
  23: rustc_driver::driver::phase_4_codegen
  24: rustc_driver::driver::compile_input::{{closure}}
  25: rustc::ty::context::tls::enter_context
  26: <std::thread::local::LocalKey<T>>::with
  27: rustc::ty::context::TyCtxt::create_and_enter
  28: rustc_driver::driver::compile_input
  29: rustc_driver::run_compiler_with_pool
  30: <scoped_tls::ScopedKey<T>>::set
  31: rustc_driver::run_compiler
  32: syntax::with_globals
  33: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:103
  34: rustc_driver::run
  35: rustc_driver::main
  36: std::rt::lang_start::{{closure}}
  37: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  38: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:103
  39: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  40: main
  41: __libc_start_main
  42: <unknown>
query stack during panic:
end of query stack
error: aborting due to previous error


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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.30.0-nightly (2f1547c0a 2018-09-11) running on x86_64-unknown-linux-gnu

@levex
Copy link
Contributor

levex commented Oct 12, 2018

No longer reproduces:

$ rustc +nightly -vV
rustc 1.31.0-nightly (77af31408 2018-10-11)
binary: rustc
commit-hash: 77af314083e5acabf9ba5335e47271f35eef2e99
commit-date: 2018-10-11
host: x86_64-unknown-linux-gnu
release: 1.31.0-nightly
LLVM version: 8.0
$ rustc +nightly 54067.rs 
error[E0669]: invalid value for constraint in inline assembly
  --> 54067.rs:9:9
   |
9  | /         asm!(
10 | |             "mov sp, $0"
11 | |              :
12 | |              : "r" (addr)
13 | |         );
   | |__________^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0669`.

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 25, 2019
@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 16, 2020
…Simulacrum

Add some regression tests

Closes rust-lang#24843
Closes rust-lang#28575
Closes rust-lang#54067
Closes rust-lang#67893
Closes rust-lang#68813

I'm not sure who's the best person to ask to review since Centril is taking a break now.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 16, 2020
…Simulacrum

Add some regression tests

Closes rust-lang#24843
Closes rust-lang#28575
Closes rust-lang#54067
Closes rust-lang#67893
Closes rust-lang#68813

I'm not sure who's the best person to ask to review since Centril is taking a break now.
@bors bors closed this as completed in b347097 Apr 17, 2020
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

7 participants