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: Unexpected non-scalars in register inputs of asm! #37433

Closed
cbiffle opened this issue Oct 27, 2016 · 4 comments · Fixed by #63259
Closed

ICE: Unexpected non-scalars in register inputs of asm! #37433

cbiffle opened this issue Oct 27, 2016 · 4 comments · Fixed by #63259
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) ❄️

Comments

@cbiffle
Copy link
Contributor

cbiffle commented Oct 27, 2016

Unexpected non-scalars in register inputs of asm! can ICE the compiler.

To reproduce:

#![feature(asm)]

fn main() {
    unsafe {
        asm!("" :: "r"(""));
    }
}

This mistake goes uncaught until it reaches this line of code where it bug!s. I would expect it to have been caught earlier, during asm! argument validation.

I've found a similar case which dumps core, which will be the subject of a separate bug.

Meta

rustc --version --verbose:
rustc 1.14.0-nightly (c59cb71 2016-10-26)
binary: rustc
commit-hash: c59cb71
commit-date: 2016-10-26
host: x86_64-unknown-linux-gnu
release: 1.14.0-nightly
LLVM version: 3.9

Backtrace:

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:655
stack backtrace:
   1:     0x7eff0357f908 - std::sys::backtrace::tracing::imp::write::h22f199c1dbb72ba2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7eff0358efbf - std::panicking::default_hook::{{closure}}::h9a389c462b6a22dd
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:247
   3:     0x7eff0358c2d5 - std::panicking::default_hook::h852b4223c1c00c59
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:257
   4:     0x7eff0358c9e7 - std::panicking::rust_panic_with_hook::hcd9d05f53fa0dafc
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:451
   5:     0x7efeffa1c5fa - std::panicking::begin_panic::h2f463d37998ebeba
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:413
   6:     0x7efeffa2c22a - rustc_errors::Handler::bug::haca77c19c882b432
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_errors/lib.rs:655
   7:     0x7eff00a752a1 - rustc::session::opt_span_bug_fmt::{{closure}}::hfeb850fbe828b399
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:727
   8:     0x7eff009b038e - rustc::session::opt_span_bug_fmt::h46e45438a860a75e
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:978
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:723
   9:     0x7eff009b01d2 - rustc::session::bug_fmt::hde22f071bf5a80ea
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/session/mod.rs:707
  10:     0x7eff02138c58 - <collections::vec::Vec<T> as core::iter::traits::FromIterator<T>>::from_iter::hc5cbb62358ceb057
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/operand.rs:82
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/rvalue.rs:168
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/ops.rs:2648
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/option.rs:383
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/iter/mod.rs:960
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcollections/vec.rs:1632
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcollections/vec.rs:1540
  11:     0x7eff021d8e65 - rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_rvalue::h2a14de75e2fd4285
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libcore/iter/iterator.rs:1196
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/rvalue.rs:167
  12:     0x7eff021c7a16 - rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_block::he67d3259f79e4177
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/statement.rs:36
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/block.rs:103
  13:     0x7eff021c5e26 - rustc_trans::mir::trans_mir::h2fb44ecb31cfdffa
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/mir/mod.rs:319
  14:     0x7eff02169d8d - rustc_trans::base::trans_closure::h941de14309416d66
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1041
  15:     0x7eff021e50a9 - rustc_trans::trans_item::TransItem::define::h2e690ccd1ee22f95
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1061
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/trans_item.rs:85
  16:     0x7eff0216d08b - rustc_trans::base::trans_crate::h9b06de31ed8799d1
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1641
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/dep_graph/graph.rs:77
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_trans/base.rs:1639
  17:     0x7eff039132a8 - rustc_driver::driver::phase_4_translate_to_llvm::hc3883ea2c4750179
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:1046
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/util/common.rs:38
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:1044
  18:     0x7eff03948f77 - rustc_driver::driver::compile_input::{{closure}}::h9162a2fa292aeb3f
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:206
  19:     0x7eff03940774 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h1928c4704cfe9c61
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:1000
  20:     0x7eff03911011 - rustc_driver::driver::phase_3_run_analysis_passes::he578df6b8805151c
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:949
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:946
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:933
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:930
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc/ty/context.rs:719
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:869
  21:     0x7eff038fa2d6 - rustc_driver::driver::compile_input::h5b63ccd49eeeb98b
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/driver.rs:172
  22:     0x7eff03923109 - rustc_driver::run_compiler::h98c7274e7cb1d11d
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:224
  23:     0x7eff03865018 - std::panicking::try::do_call::h99ed0da044e497c3
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:1148
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:137
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/librustc_driver/lib.rs:1082
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:255
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:356
  24:     0x7eff03596eca - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libpanic_unwind/lib.rs:97
  25:     0x7eff03883028 - <F as alloc::boxed::FnBox<A>>::call_box::hbdd5a14cd8e33b97
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:332
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:311
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/thread/mod.rs:278
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/liballoc/boxed.rs:595
  26:     0x7eff0358ac84 - std::sys::thread::Thread::new::thread_start::h50b05608a499d2b2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/liballoc/boxed.rs:605
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/sys/unix/thread.rs:84
  27:     0x7efefb8b7453 - start_thread
  28:     0x7eff0325a7de - __GI___clone
  29:                0x0 - <unknown>
@TimNN TimNN added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Oct 28, 2016
@Mark-Simulacrum
Copy link
Member

Got an updated backtrace:

error: internal compiler error: src/librustc_trans/mir/operand.rs:111: not immediate: OperandRef(Pair((i8*:i8* getelementptr inbounds ([0 x i8], [0 x i8]* @str.0, i32 0, i32 0)), (i64:i64 0)) @ &str)

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>', src/librustc_errors/lib.rs:473
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
...
  13: rustc_trans::mir::operand::OperandRef::immediate
             at /rust/src/librustc_trans/mir/operand.rs:111
  14: core::ops::impls::<impl core::ops::FnOnce<A> for &'a mut F>::call_once
             at /rust/src/librustc_trans/mir/statement.rs:83
             at /rust/src/libcore/ops.rs:2710
  15: <collections::vec::Vec<T> as collections::vec::SpecExtend<T, I>>::spec_extend
             at /rust/src/libcore/option.rs:392
             at /rust/src/libcore/iter/mod.rs:1011
             at /rust/src/libcollections/vec.rs:1760
  16: <collections::vec::Vec<T> as collections::vec::SpecExtend<T, I>>::from_iter
             at /rust/src/libcollections/vec.rs:1743
  17: rustc_trans::mir::statement::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_statement
             at /rust/src/libcollections/vec.rs:1630
             at /rust/src/libcore/iter/iterator.rs:1222
             at /rust/src/librustc_trans/mir/statement.rs:82
  18: rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block
             at /rust/src/librustc_trans/mir/block.rs:109
  19: rustc_trans::mir::trans_mir
             at /rust/src/librustc_trans/mir/mod.rs:330
  20: rustc_trans::base::trans_instance
             at /rust/src/librustc_trans/base.rs:606
  21: rustc_trans::trans_item::TransItem::define
             at /rust/src/librustc_trans/trans_item.rs:104
  22: rustc_trans::base::trans_crate::module_translation
             at /rust/src/librustc_trans/base.rs:1182
  23: rustc::dep_graph::graph::DepGraph::with_task
             at /rust/src/librustc/dep_graph/graph.rs:111
  24: core::ops::impls::<impl core::ops::FnOnce<A> for &'a mut F>::call_once
             at /rust/src/librustc_trans/base.rs:1116
             at /rust/src/libcore/ops.rs:2710
  25: <collections::vec::Vec<T> as collections::vec::SpecExtend<T, I>>::spec_extend
             at /rust/src/libcore/option.rs:392
             at /rust/src/libcore/iter/mod.rs:1011
             at /rust/src/libcollections/vec.rs:1760
  26: <collections::vec::Vec<T> as collections::vec::SpecExtend<T, I>>::from_iter
             at /rust/src/libcollections/vec.rs:1743
  27: rustc_trans::base::trans_crate
             at /rust/src/libcollections/vec.rs:1630
             at /rust/src/libcore/iter/iterator.rs:1222
             at /rust/src/librustc_trans/base.rs:1111
  28: rustc::util::common::time
             at /rust/src/librustc_driver/driver.rs:1051
             at /rust/src/librustc/util/common.rs:48
  29: rustc_driver::driver::phase_4_translate_to_llvm
             at /rust/src/librustc_driver/driver.rs:1049
  30: rustc_driver::driver::compile_input::{{closure}}
             at /rust/src/librustc_driver/driver.rs:206
  31: <std::thread::local::LocalKey<T>>::with
             at /rust/src/librustc_driver/driver.rs:1032
             at /rust/src/librustc/ty/context.rs:915
             at /rust/src/libstd/thread/local.rs:253
  32: rustc::ty::context::tls::enter
             at /rust/src/librustc/ty/context.rs:912
  33: <std::thread::local::LocalKey<T>>::with
             at /rust/src/librustc/ty/context.rs:899
             at /rust/src/libstd/thread/local.rs:253
  34: rustc::ty::context::tls::enter_global
             at /rust/src/librustc/ty/context.rs:896
  35: rustc::ty::context::TyCtxt::create_and_enter
             at /rust/src/librustc/ty/context.rs:706
  36: rustc_driver::driver::phase_3_run_analysis_passes
             at /rust/src/librustc_driver/driver.rs:940
  37: rustc_driver::driver::compile_input
             at /rust/src/librustc_driver/driver.rs:172
  38: rustc_driver::run_compiler
             at /rust/src/librustc_driver/lib.rs:224

@gmorenz
Copy link

gmorenz commented Jun 2, 2017

Ran into this with

#![feature(asm)]

#[repr(C)]
struct MyPtr(usize);

fn main() {
    unsafe {
        let target = MyPtr(0);
        asm!( "ret" : : "{rdi}"(target) );
    }
}

which I would sort of hope would just work. Backtrace is identical (at least as far as a compiler without debugging information outputs).

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@istankovic
Copy link
Contributor

Still reproducible with rustc 1.26.0-nightly (adf2135ad 2018-03-17).

@levex
Copy link
Contributor

levex commented Oct 12, 2018

No longer reproduces:

$ rustc +nightly 37433.rs
error[E0669]: invalid value for constraint in inline assembly
 --> 37433.rs:5:9
  |
5 |         asm!("" :: "r"(""));
  |         ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0669`.
$ rustc +nightly 37433-2.rs 
error[E0669]: invalid value for constraint in inline assembly
 --> 37433-2.rs:9:9
  |
9 |         asm!( "ret" : : "{rdi}"(target) );
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0669`.
$ 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

@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 Aug 4, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 5, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 6, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 7, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 7, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 8, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 8, 2019
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) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants