Closed
Description
Code
I worked out this minimal reproducible example from some code I've been working on. Changing almost anything about this causes the compiler crash to go away, which probably makes it a little hard to figure out what's going on here. I've checked and performing a release build, or a debug build with an opt level >= 1 will cause the compiler to SIGSEGV. Clearing the target dir, switching between stable/nightly, reinstalling toolchains, updating my system etc. didn't have an effect.
// lib.rs - minimal reproducible example
// // -------- -------- // //
// Adding an interger #[repr(?)] fixes the crash, except for u8, i8 & i16 (?)
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum EnumValue {
// Removing any of these fixes it (?)
A = 0,
B = 1,
C = 2,
D = 3,
}
impl EnumValue {
pub fn map_value(self) -> usize {
// Changing anything in this mapping fixes it (?)
match self {
EnumValue::A => 0,
EnumValue::B => 1,
EnumValue::C => 2,
EnumValue::D => 0,
}
}
}
// // -------- -------- // //
pub trait ProviderTrait {
fn get(&self, value: EnumValue) -> u64;
}
// // -------- -------- // //
// Removing the lifetime fixes it (?)
pub struct ProviderTraitImpl<'a> {
// Moving the lifetime out of the inner array or to the inner `u64` fixes it (?)
pub data: [&'a [u64; 3]; 4],
}
// Not implementing the trait fixes it (?)
impl<'a> ProviderTrait for ProviderTraitImpl<'a> {
fn get(&self, value: EnumValue) -> u64 {
// Changing almost anything in here fixes it (?)
if value < EnumValue::D {
self.data[value as usize][value.map_value()]
} else {
self.data[3][value.map_value()]
}
}
}
Meta
Occurs in both Stable and Nightly.
rustc +stable --version --verbose
:
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
rustc +nightly --version --verbose
:
rustc 1.81.0-nightly (6292b2af6 2024-07-02)
binary: rustc
commit-hash: 6292b2af620dbd771ebb687c3a93c69ba8f97268
commit-date: 2024-07-02
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7
Error output
> RUST_BACKTRACE=1 cargo build --release --verbose
Compiling sigsegv-mre v0.1.0 (/home/nyatalie/Dev/Misc/RustCrash)
Running `/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name sigsegv_mre --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=212 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=e25b70c6bc8e498d -C extra-filename=-e25b70c6bc8e498d --out-dir /home/nyatalie/Dev/Misc/RustCrash/target/release/deps -C strip=debuginfo -L dependency=/home/nyatalie/Dev/Misc/RustCrash/target/release/deps`
error: rustc interrupted by SIGSEGV, printing backtrace
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x2ea5963)[0x7712886a5963]
/usr/lib/libc.so.6(+0x3cae0)[0x771285650ae0]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(+0x60d54d7)[0x771283cd54d7]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(+0x60d7e96)[0x771283cd7e96]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(+0x60d3bdc)[0x771283cd3bdc]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xad4)[0x771283939714]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x771283938b85]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.18.1-rust-1.79.0-stable(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x260)[0x771283e7a474]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(LLVMRustWriteOutputFile+0x190)[0x77128a568790]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x4d683a8)[0x77128a5683a8]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x4d6603f)[0x77128a56603f]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x4d65d21)[0x77128a565d21]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x4d6409b)[0x77128a56409b]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-1ccb730c51a3970e.so(+0x4d63667)[0x77128a563667]
/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libstd-d5189b81a4fa4d36.so(rust_metadata_std_3c8ba8ebcf555201+0xc3cab)[0x77128baa4cab]
/usr/lib/libc.so.6(+0x92ded)[0x7712856a6ded]
/usr/lib/libc.so.6(+0x1160dc)[0x77128572a0dc]
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
error: could not compile `sigsegv-mre` (lib)
Caused by:
process didn't exit successfully: `/home/nyatalie/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name sigsegv_mre --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=212 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=e25b70c6bc8e498d -C extra-filename=-e25b70c6bc8e498d --out-dir /home/nyatalie/Dev/Misc/RustCrash/target/release/deps -C strip=debuginfo -L dependency=/home/nyatalie/Dev/Misc/RustCrash/target/release/deps` (signal: 11, SIGSEGV: invalid memory reference)
No backtrace was output.
Also attempted to enable LLVM assertions and saw no change in output.
Increasing stack size, as per advice, had no effect.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Relevant to the compiler team, which will review and decide on the PR/issue.Issue expected to be fixed by the next major LLVM upgrade, or backported fixes