Skip to content

write_volatile causes ICE with zero-sized types. #39827

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
ghost opened this issue Feb 14, 2017 · 1 comment
Closed

write_volatile causes ICE with zero-sized types. #39827

ghost opened this issue Feb 14, 2017 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ghost
Copy link

ghost commented Feb 14, 2017

I tried this code:

fn main () {
    let mut x = ();
    unsafe {
        std::ptr::write_volatile(&mut x, ());
    }
}

I expected to see this happen:

Nothing

Instead, this happened:

error: internal compiler error: unexpected panic

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 'index out of bounds: the len is 1 but the index is 1', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/librustc_trans/intrinsic.rs:326

Meta

rustc --version --verbose:

rustc 1.17.0-nightly (956e2bcba 2017-02-12)
binary: rustc
commit-hash: 956e2bcbaa00c05e051718b1375375915064f1c3
commit-date: 2017-02-12
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9

Backtrace:

   1:     0x7fdf6f9393fa - std::sys::imp::backtrace::tracing::imp::write::h3188f035833a2635
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7fdf6f94775f - std::panicking::default_hook::{{closure}}::h6385b6959a2dd25b
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:349
   3:     0x7fdf6f9472fd - std::panicking::default_hook::he4f3b61755d7fa95
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:359
   4:     0x7fdf6f947c07 - std::panicking::rust_panic_with_hook::hf00b8130f73095ec
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:553
   5:     0x7fdf6f947a44 - std::panicking::begin_panic::h6227f62cb2cdaeb4
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:515
   6:     0x7fdf6f9479b9 - std::panicking::begin_panic_fmt::h173eadd80ae64bec
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:499
   7:     0x7fdf6f947947 - rust_begin_unwind
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:475
   8:     0x7fdf6f98323d - core::panicking::panic_fmt::h3b2d1e30090844ff
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69
   9:     0x7fdf6f9831e8 - core::panicking::panic_bounds_check::hecd7d6e6ce8d6275
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:56
  10:     0x7fdf6eb9d8db - rustc_trans::intrinsic::trans_intrinsic_call::h71c3926493851d2f
  11:     0x7fdf6ebaf26a - rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'bcx, 'tcx>>::trans_block::h7370a41d2cf00e4c
  12:     0x7fdf6eba9498 - rustc_trans::mir::trans_mir::ha7607c24e74fe3fc
  13:     0x7fdf6ebcacee - rustc_trans::trans_item::TransItem::define::h1e41c90c4e3659f0
  14:     0x7fdf6eb42827 - rustc_trans::base::trans_crate::hd0c42f1c088c6870
  15:     0x7fdf6fcebc10 - rustc_driver::driver::phase_4_translate_to_llvm::haac68055ca0e54a5
  16:     0x7fdf6fcb9819 - rustc_driver::driver::compile_input::{{closure}}::ha32b4e7a1ff999dd
  17:     0x7fdf6fcdf091 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h16429aca33e82f30
  18:     0x7fdf6fcc85fe - rustc_driver::driver::phase_3_run_analysis_passes::h1b30709031b4f637
  19:     0x7fdf6fcb7775 - rustc_driver::driver::compile_input::h71ecf4df05846d25
  20:     0x7fdf6fd00b62 - rustc_driver::run_compiler::h180324a0694503f7
  21:     0x7fdf6fc1547b - std::panicking::try::do_call::ha2c776608407d6f3
  22:     0x7fdf6f95042a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  23:     0x7fdf6fc37021 - <F as alloc::boxed::FnBox<A>>::call_box::h08c51ed50888bb2f
  24:     0x7fdf6f9465c4 - std::sys::imp::thread::Thread::new::thread_start::he018521f53b24939
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/liballoc/boxed.rs:615
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  25:     0x7fdf68784453 - start_thread
  26:     0x7fdf6f6107de - __GI___clone
  27:                0x0 - <unknown>
@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 15, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
bors added a commit that referenced this issue Aug 13, 2017
Fix for issue #39827

*Cause of the issue*

While preparing for `trans_intrinsic_call()` invoke arguments are processed with `trans_argument()` method which excludes zero-sized types from argument list (to be more correct - all arguments for which `ArgKind` is `Ignore` are filtered out). As result `volatile_store()` intrinsic gets one argument instead of expected address and value.

*How it is fixed*

Modification of the `trans_argument()` method may cause side effects, therefore change was implemented in `volatile_store()` intrinsic building code itself. Now it checks function signature and if it was specialised with zero-sized type, then emits `C_nil()` instead of accessing non-existing second argument.
@eminence
Copy link
Contributor

This bug is no longer reproducible in the current stable/beta/nightly compilers. This issue can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants