opened
sp3d
username_0
Compiling the following program with `rustc -g` fails an LLVM assertion:
```
#![feature(core)]
#![crate_type = "lib"]

extern crate core;
use core::raw::Repr;

pub struct Dst {
	pub a: (),
	pub b: (),
	pub data: [u8],
}

pub unsafe fn borrow(bytes: &[u8]) -> &Dst {
	let slice = bytes.repr();
	let dst: &Dst = std::mem::transmute((slice.data, slice.len));
	dst
}
```

```
$ rustc -g crash-rustc-g.rs 
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/include/llvm/IR/DataLayout.h:484: uint64_t llvm::StructLayout::getElementOffset(unsigned int) const: Assertion `Idx < NumElements && "Invalid element idx!"' failed.
```

This is basically a minimal test-case, as removing pretty much anything (including fields a or b!) avoids the assertion. Similarly, compiling without `-g` does not produce an assertion failure.

The backtrace looks like this:
```
#0  0x00007ffff6ff44b7 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff6ff588a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff6fed41d in __assert_fail_base () from /usr/lib/libc.so.6
#3  0x00007ffff6fed4d2 in __assert_fail () from /usr/lib/libc.so.6
#4  0x00007ffff2fd009d in LLVMOffsetOfElement () from /usr/local/lib/librustc_llvm-4e7c5e5c.so
#5  0x00007ffff6c84326 in iter::Map$LT$I$C$$u20$F$GT$.Iterator::next::h1347171284529675023 () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#6  0x00007ffff6c7e375 in trans::debuginfo::set_members_of_composite_type::h557c9a9bddb8036bKSE () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#7  0x00007ffff6c7d24c in trans::debuginfo::RecursiveTypeDescription$LT$$u27$tcx$GT$::finalize::hcc3c0cb5c91492bb7oE () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#8  0x00007ffff6c76fe3 in trans::debuginfo::type_metadata::h6cb0d45057c320e9U8E () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#9  0x00007ffff6c78031 in trans::debuginfo::type_metadata::h6cb0d45057c320e9U8E () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#10 0x00007ffff6c85083 in trans::debuginfo::subroutine_type_metadata::he917a06bcf81ed42u4E () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#11 0x00007ffff6c764b4 in trans::debuginfo::type_metadata::h6cb0d45057c320e9U8E () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#12 0x00007ffff6c0fb87 in trans::debuginfo::create_function_debug_context::h603196dd6899b3baGMD () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#13 0x00007ffff6b4d0e8 in trans::base::new_fn_ctxt::heff0d89eaf6a93a31Vs () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#14 0x00007ffff6c15178 in trans::base::trans_closure::h295e0a8c0302a522Rjt () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#15 0x00007ffff6b28f59 in trans::base::trans_fn::h475c276dfb9092deKut () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#16 0x00007ffff6b24bb2 in trans::base::trans_item::hc022dcad9f32230fCSt () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#17 0x00007ffff6c2158d in trans::base::trans_crate::ha116a53daafe15a4fPu () from /usr/local/lib/librustc_trans-4e7c5e5c.so
#18 0x00007ffff7afe554 in driver::phase_4_translate_to_llvm::hb0c3ed9b413b640akOa () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#19 0x00007ffff7ada144 in driver::compile_input::h56dbe0e66fe8a956Rba () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#20 0x00007ffff7b91a43 in run_compiler::hbbbe30f1ad654d0ex2b () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#21 0x00007ffff7b8f88d in thunk::F.Invoke$LT$A$C$$u20$R$GT$::invoke::h9510793753674638958 () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#22 0x00007ffff7b8e911 in rt::unwind::try::try_fn::h15118916039308917284 () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#23 0x00007ffff7561f59 in rust_try_inner () from /usr/local/lib/libstd-4e7c5e5c.so
#24 0x00007ffff7561f46 in rust_try () from /usr/local/lib/libstd-4e7c5e5c.so
#25 0x00007ffff7b8edb7 in thunk::F.Invoke$LT$A$C$$u20$R$GT$::invoke::h8595907971712275588 () from /usr/local/lib/librustc_driver-4e7c5e5c.so
#26 0x00007ffff74df996 in sys::thread::thread_start::h9f0c06661d546448B1G () from /usr/local/lib/libstd-4e7c5e5c.so
#27 0x00007ffff13a7374 in start_thread () from /usr/lib/libpthread.so.0
#28 0x00007ffff70a927d in clone () from /usr/lib/libc.so.6
```

Rustc version is `rustc 1.0.0-nightly (30e1f9a1c 2015-03-14) (built 2015-03-15)`.
LLVM assertion failure when on struct with unsized trailing field
issue
created
michaelwoerister
username_1
Nice catch! Thanks a lot for the report and the great test case.
comment
created
alexcrichton
username_2
This has apparently since been fixed, yay!
comment
created
c3st7n
username_3
Raised a PR to add test case: https://github.com/rust-lang/rust/pull/34243
comment
closed
bors
username_4
issue