Skip to content

Rust nightly internal compiler error with inline assembly #38735

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

Closed
iankronquist opened this issue Dec 31, 2016 · 6 comments
Closed

Rust nightly internal compiler error with inline assembly #38735

iankronquist opened this issue Dec 31, 2016 · 6 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@iankronquist
Copy link

iankronquist commented Dec 31, 2016

error: internal compiler error:
/buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/mir/operand.rs:82: 
impossible case reached

Interesting part of the code:

fn lidt(idt_desc : CPUTableDescriptor) {
    unsafe {
        asm!(
            "lidt $0"
            :
            : "m"(idt_desc)
            :
            );
    }
}

Expected behavior: it compiles with unused code warnings.
Actual behavior: internal compiler error.

Playground:
https://play.rust-lang.org/?gist=632e0e9fe4d75f417647ea847de2c97e&version=nightly&backtrace=0

Gist:
https://gist.github.com/anonymous/632e0e9fe4d75f417647ea847de2c97e

Meta

Version:

rustc 1.16.0-nightly (4ecc85beb 2016-12-28)
binary: rustc
commit-hash: 4ecc85beb339aa8089d936e450b0d800bdf580ae
commit-date: 2016-12-28
host: x86_64-apple-darwin
release: 1.16.0-nightly
LLVM version: 3.9

Backtrace:

warning: struct is never used: `CPUTableDescriptor`, #[warn(dead_code)] on by default
 --> test.rs:4:1
  |
4 |   struct CPUTableDescriptor {
  |  _^ starting here...
5 | |     limit: u16,
6 | |     base: u64,
7 | | }
  | |_^ ...ending here

warning: function is never used: `lidt`, #[warn(dead_code)] on by default
  --> test.rs:10:1
   |
10 | fn lidt(idt_desc : CPUTableDescriptor) {
   | ^

error: internal compiler error: /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_trans/mir/operand.rs:82: impossible case reached

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_errors/lib.rs:423
stack backtrace:
   1:        0x10978e57c - std::sys::imp::backtrace::tracing::imp::write::h36c82bddc32ee014
   2:        0x10979abee - std::panicking::default_hook::{{closure}}::h5befc2c9c6395cdf
   3:        0x10979a793 - std::panicking::default_hook::hc066c0e0f8dcf194
   4:        0x10979b0b6 - std::panicking::rust_panic_with_hook::hb2f44ed7df6389fd
   5:        0x10955660a - std::panicking::begin_panic::haeee16f630c8e0dd
   6:        0x10956af74 - rustc_errors::Handler::bug::h0a6dfee529085c47
   7:        0x106067ffc - rustc::session::opt_span_bug_fmt::{{closure}}::h2346c93e9b59d005
   8:        0x106067e09 - rustc::session::opt_span_bug_fmt::hc2c6b26c2bc79667
   9:        0x10606798a - rustc::session::bug_fmt::hcef19d8a185b5c67
  10:        0x1050d6d36 - rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_rvalue::h9bcb60b9dc13b20d
  11:        0x1050c32dd - rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block::hb09551580d7d1bc1
  12:        0x1050c0d61 - rustc_trans::mir::trans_mir::h3707144f527a1201
  13:        0x1050e2289 - rustc_trans::trans_item::TransItem::define::h13de84b7cdc015ac
  14:        0x1050631a0 - rustc_trans::base::trans_crate::h8a7222dad18bc82c
  15:        0x104e20d1b - rustc_driver::driver::phase_4_translate_to_llvm::h7f500c73742c1147
  16:        0x104defd1a - rustc_driver::driver::compile_input::{{closure}}::h27127734b2781be8
  17:        0x104e1473f - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h5aaf72d203c8f56a
  18:        0x104dfe50f - rustc_driver::driver::phase_3_run_analysis_passes::h52c41e1c71fdeff7
  19:        0x104dee118 - rustc_driver::driver::compile_input::h288ea94170be9057
  20:        0x104e357eb - rustc_driver::run_compiler::ha8e57199bffb1089
  21:        0x104d45158 - std::panicking::try::do_call::h4527918aedb10721
  22:        0x10979dcaa - __rust_maybe_catch_panic
  23:        0x104d6f7e3 - <F as alloc::boxed::FnBox<A>>::call_box::hf4f3e505436bf553
  24:        0x109799d24 - std::sys::imp::thread::Thread::new::thread_start::h0986e95fd3be13c5
  25:     0x7fff9613299c - _pthread_body
  26:     0x7fff96132919 - _pthread_start


@sanxiyn sanxiyn added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Dec 31, 2016
@Amanieu
Copy link
Member

Amanieu commented Dec 31, 2016

Generally the "m" constraint is broken. You should use an indirect memory constraint instead:

fn lidt(idt_desc : CPUTableDescriptor) {
    unsafe {
        asm!(
            "lidt $0"
            :
            : "*m"(&idt_desc)
            :
            );
    }
}

@iankronquist
Copy link
Author

I was able to work around it by using a register operand, but the compiler told me it was a bug so I reported it.

@brson brson added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jan 1, 2017
@brson
Copy link
Contributor

brson commented Jan 1, 2017

Great report. Thanks @iankronquist!

@cyplo
Copy link
Contributor

cyplo commented Nov 1, 2017

Still crashing on rustc 1.23.0-nightly (8b22e70 2017-10-31)

@levex
Copy link
Contributor

levex commented Sep 27, 2018

No longer reproduces:

$ cat 38785.rs
#![feature(asm)]


struct CPUTableDescriptor {
    limit: u16,
    base: u64,
}


fn lidt(idt_desc : CPUTableDescriptor) {
    unsafe {
        asm!(
            "lidt $0"
            :
            : "m"(idt_desc)
            :
            );
    }
}

fn main() { }

$ rustc +nightly -vV
rustc 1.30.0-nightly (2f1547c0a 2018-09-11)
binary: rustc
commit-hash: 2f1547c0aa5957b42cc768c00119c6eb7b4262d3
commit-date: 2018-09-11
host: x86_64-unknown-linux-gnu
release: 1.30.0-nightly
LLVM version: 8.0
$ rustc +nightly 38785.rs 
warning: struct is never constructed: `CPUTableDescriptor`
 --> 38785.rs:4:1
  |
4 | struct CPUTableDescriptor {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

warning: function is never used: `lidt`
  --> 38785.rs:10:1
   |
10 | fn lidt(idt_desc : CPUTableDescriptor) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

$ echo $status
0

@steveklabnik
Copy link
Member

Great! I'm going to close this, then. If anyone sees this come back up, please let me know and we can re-open!

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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

8 participants