Closed
Description
I get a segfault when I try to run cargo test
on the following code:
# Cargo.toml
[package]
name = "rustc-segfault"
edition = "2021"
// src/lib.rs
#[repr(C, align(8))]
pub struct ConstantReader<T> {
pub phantom: core::marker::PhantomData<T>,
pub words: &'static [u64],
}
pub mod test_constants {
pub static VOID_LIST_CONST: crate::ConstantReader<usize> = {
pub static WORDS: [u64; 1] = [0];
crate::ConstantReader {
phantom: ::std::marker::PhantomData,
words: &WORDS,
}
};
}
#[test]
fn test_constants() {
let _ = test_constants::VOID_LIST_CONST.words.as_ptr();
}
% rustc -vV
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
% cargo test
Compiling rustc-segfault v0.0.0 (/Users/dwrensha/Desktop/rustc-segfault)
error: could not compile `rustc-segfault` (lib test)
Caused by:
process didn't exit successfully: `/Users/dwrensha/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name rustc_segfault --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=179 --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --test -C metadata=47a41d92fd841df5 -C extra-filename=-47a41d92fd841df5 --out-dir /Users/dwrensha/Desktop/rustc-segfault/target/debug/deps -C incremental=/Users/dwrensha/Desktop/rustc-segfault/target/debug/incremental -L dependency=/Users/dwrensha/Desktop/rustc-segfault/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)
I see the same behavior with the latest nightly rustc
. I see no error with rustc
1.77.0 or earlier. It also works fine on Linux, and on an older Intel Macbook.
I also updated to the latest XCode to make sure all parts of my toolchain were up to date. Doing so did not make the segfault go away.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Incremental compilationCategory: This is a bug.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Operating system: macOSRelevant 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