Skip to content

ICE: repr align with extern "C" functions (). #45662

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
matthewjasper opened this issue Oct 31, 2017 · 3 comments
Closed

ICE: repr align with extern "C" functions (). #45662

matthewjasper opened this issue Oct 31, 2017 · 3 comments
Labels
A-FFI Area: Foreign function interface (FFI) C-bug Category: This is a bug. 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

@matthewjasper
Copy link
Contributor

matthewjasper commented Oct 31, 2017

The following code ICEs on x86_64 linux

#![feature(repr_align)]
#![feature(attr_literals)]

#[repr(align(16))]
pub struct A {
    y: i64, // Can be any type
}

pub extern "C" fn foo(x: A) {}

Suspect that it's this line (expecting that a struct with size > 8 has > 1 field)

let hi = reg_component(cls, &mut i, size - offset).unwrap();

ICE message:

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.22.0-nightly (8493813cd 2017-10-22) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:335:20
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:58
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::panicking::panic
             at /checkout/src/libcore/panicking.rs:51
  10: _ZN11rustc_trans11cabi_x86_6416compute_abi_info28_$u7b$$u7b$closure$u7d$$u7d$17h9fac6bc7bad7473bE.llvm.D51027F6
  11: _ZN11rustc_trans3abi6FnType14adjust_for_abi17h1b7f713077d90b22E.llvm.795B9FFD
  12: rustc_trans::declare::declare_fn
  13: rustc_trans::trans_item::predefine_fn
  14: rustc_trans::trans_item::TransItemExt::predefine
  15: _ZN11rustc_trans4base20compile_codegen_unit17h362937ee897385e2E.llvm.FBB1C193
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::compute_result
  17: rustc::dep_graph::graph::DepGraph::with_task
  18: rustc_errors::Handler::track_diagnostics
  19: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  20: _ZN5rustc2ty4maps80_$LT$impl$u20$rustc..ty..maps..queries..compile_codegen_unit$LT$$u27$tcx$GT$$GT$5force17h9c0ad53b14788757E.llvm.83EA5DAA
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
  22: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
  23: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
  24: rustc_trans::base::trans_crate
  25: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  26: rustc::util::common::time
  27: rustc_driver::driver::phase_4_translate_to_llvm
  28: _ZN12rustc_driver6driver13compile_input28_$u7b$$u7b$closure$u7d$$u7d$17h7eb7268ddd3dec6bE.llvm.5A1A36ED
  29: <std::thread::local::LocalKey<T>>::with
  30: <std::thread::local::LocalKey<T>>::with
  31: rustc_driver::driver::compile_input
  32: rustc_driver::run_compiler

cc #33626

@estebank estebank added A-FFI Area: Foreign function interface (FFI) C-bug Category: This is a bug. 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. labels Oct 31, 2017
topecongiro added a commit to topecongiro/rust that referenced this issue Dec 26, 2017
bors added a commit that referenced this issue Dec 27, 2017
Add tests to fixed ICEs

Closes #27078. Closes #27985. Closes #39848. Closes #42164.
Closes #42479. Closes #45662. Closes #45965. Closes #46152.
@matthewjasper
Copy link
Contributor Author

This isn't fixed, example should have had a #![crate_type = "lib"] or a #[no_mangle] attribute to make sure that the function is exported.
@estebank

@estebank estebank reopened this Dec 28, 2017
@estebank
Copy link
Contributor

@eddyb
Copy link
Member

eddyb commented Jan 12, 2018

Suspect that it's this line (expecting that a struct with size > 8 has > 1 field)

These "components" are not exactly struct fields, but rather hardware registers. The alignment padding probably triggers an edge case, I'll have to look deeper.

topecongiro added a commit to topecongiro/rust that referenced this issue Jan 14, 2018
Add a test for rust-lang#38763.
Update a test for rust-lang#45662.
topecongiro added a commit to topecongiro/rust that referenced this issue Jan 14, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 25, 2018
rustc_trans: ignore trailing padding larger than 8 bytes.

Fixes rust-lang#45662 by ignoring a missing second register component, as it could be entirely padding.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-FFI Area: Foreign function interface (FFI) C-bug Category: This is a bug. 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

3 participants