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 in presence of bang type #50570

Closed
bjorn3 opened this issue May 9, 2018 · 2 comments
Closed

ICE in presence of bang type #50570

bjorn3 opened this issue May 9, 2018 · 2 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@bjorn3
Copy link
Member

bjorn3 commented May 9, 2018

This test is compile-fail/never_transmute_humans.rs from miri

// This should fail even without validation
// compile-flags: -Zmir-emit-validate=0

#![feature(never_type)]
#![allow(unreachable_code)]
#![allow(unused_variables)]

struct Human;

fn main() {
    let x: ! = unsafe {
        std::mem::transmute::<Human, !>(Human) //~ ERROR entered unreachable code
    };
    f(x)
}

fn f(x: !) -> ! { x }
backtrace
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:335:21
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: rustc_trans::mir::block::<impl rustc_trans::mir::FunctionCx<'a, 'tcx>>::trans_terminator
  11: rustc_trans::mir::trans_mir
  12: rustc_trans::base::trans_instance
  13: rustc_trans::trans_item::MonoItemExt::define
  14: rustc_trans::base::compile_codegen_unit
  15: rustc::ty::maps::<impl rustc::ty::maps::config::QueryConfig<'tcx> for rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::compute
  16: rustc::dep_graph::graph::DepGraph::with_task_impl
  17: rustc::ty::context::tls::with_related_context
  18: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  19: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  20: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
  21: rustc_trans::base::trans_crate
  22: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  23: rustc::util::common::time
  24: rustc_driver::driver::phase_4_translate_to_llvm
  25: rustc_driver::driver::compile_input::{{closure}}
  26: rustc::ty::context::tls::enter_context
  27: <std::thread::local::LocalKey<T>>::with
  28: rustc::ty::context::TyCtxt::create_and_enter
  29: rustc_driver::driver::compile_input
  30: rustc_driver::run_compiler_impl
  31: <scoped_tls::ScopedKey<T>>::set
  32: syntax::with_globals
  33: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  34: __rust_maybe_catch_panic
  35: rustc_driver::run
  36: rustc_driver::main
  37: std::rt::lang_start::{{closure}}
  38: std::panicking::try::do_call
  39: __rust_maybe_catch_panic
  40: std::rt::lang_start_internal
  41: main
query stack during panic:
#0 [compile_codegen_unit] compile_codegen_unit
end of query stack

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: rustc 1.27.0-nightly (8ff4b4206 2018-05-08) running on x86_64-apple-darwin
@varkor
Copy link
Member

varkor commented May 9, 2018

There's some discussion of mem::transmute with ! here: rust-lang/rfcs#1892. However, it doesn't look like anything was decided in terms of forbidding it since rust-lang/rfcs#1891 was closed.

@pietroalbini pietroalbini added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. labels May 9, 2018
@RalfJung
Copy link
Member

RalfJung commented May 9, 2018

This code is insta-UB if it ever gets executed, but it should still not ICE, obviously.

bors added a commit that referenced this issue May 20, 2018
Fix an ICE when attempting to transmute an uninhabited type

Fixes #50570.
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

4 participants