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

Taking a reference to a static with an extern type ICEs #57876

Closed
mehcode opened this issue Jan 24, 2019 · 3 comments
Closed

Taking a reference to a static with an extern type ICEs #57876

mehcode opened this issue Jan 24, 2019 · 3 comments
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mehcode
Copy link
Contributor

mehcode commented Jan 24, 2019

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=19c98852cf33b7b65ec942629c6ced44

#![feature(extern_types)]

extern "C" {
    type Foo;
    static FOO: Foo;
}

fn main() {
    let foo = unsafe { &FOO };
}

thread 'rustc' panicked at 'assertion failed: !layout.is_unsized()', src/librustc_codegen_ssa/mir/place.rs:35:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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.33.0-nightly (7bac68a5d 2019-01-21) running on x86_64-apple-darwin

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

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

$ rustc -V
rustc 1.33.0-nightly (7bac68a5d 2019-01-21)
@hellow554
Copy link
Contributor

hellow554 commented Jan 24, 2019

@mehcode please provide a backtracke in the future, but thanks anyway for the report! ❤️

warning: unused variable: `foo`
 --> src/main.rs:9:9
  |
9 |     let foo = unsafe { &FOO };
  |         ^^^ help: consider using `_foo` instead
  |
  = note: #[warn(unused_variables)] on by default

thread 'rustc' panicked at 'assertion failed: !layout.is_unsized()', src/librustc_codegen_ssa/mir/place.rs:35:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::begin_panic
   7: rustc_codegen_ssa::mir::place::<impl rustc_codegen_ssa::mir::FunctionCx<'a, 'tcx, Bx>>::codegen_place
   8: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<'a, 'tcx, Bx>>::codegen_rvalue_operand
   9: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<'a, 'tcx, Bx>>::codegen_rvalue
  10: rustc_codegen_ssa::mir::codegen_mir
  11: rustc_codegen_ssa::base::codegen_instance
  12: rustc_codegen_ssa::mono_item::MonoItemExt::define
  13: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  14: rustc::dep_graph::graph::DepGraph::with_task
  15: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16: rustc_codegen_ssa::base::codegen_crate
  17: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  18: rustc::util::common::time
  19: rustc_driver::driver::phase_4_codegen
  20: rustc_driver::driver::compile_input::{{closure}}
  21: <std::thread::local::LocalKey<T>>::with
  22: rustc::ty::context::TyCtxt::create_and_enter
  23: rustc_driver::driver::compile_input
  24: <scoped_tls::ScopedKey<T>>::set
  25: rustc_driver::run_compiler
  26: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
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.33.0-nightly (19f8958f8 2019-01-23) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

@hellow554
Copy link
Contributor

cc #43467

@Centril Centril added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 24, 2019
@estebank estebank added the A-codegen Area: Code generation label Jan 24, 2019
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 28, 2019
@dlrobertson
Copy link
Contributor

Looks like this was introduced by #55257, but the reasoning for the change seems sound. I think the handling of a static Place in codegen_place should properly handle unsized types.

kennytm added a commit to kennytm/rust that referenced this issue Feb 7, 2019
Do not ICE in codegen when using a extern_type static

The layout of a extern_type static is unsized, but may pass the
Well-Formed check in typeck (See rust-lang#55257).  As a result, we
cannot assume that a static is sized when generating the `Place`
for an r-value.

Fixes: rust-lang#57876

r? @oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants