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

rustc 1.78.0 segfault on MacOS / M1 #125053

Closed
dwrensha opened this issue May 12, 2024 · 7 comments · Fixed by #125288
Closed

rustc 1.78.0 segfault on MacOS / M1 #125053

dwrensha opened this issue May 12, 2024 · 7 comments · Fixed by #125288
Labels
A-incr-comp Area: Incremental compilation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dwrensha
Copy link
Contributor

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.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 12, 2024
@dwrensha
Copy link
Contributor Author

The problem disappears if I turn off incremental compilation by adding this to the Cargo.toml:

[profile.dev]
incremental = false

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-incr-comp Area: Incremental compilation O-macos Operating system: macOS labels May 13, 2024
@lqd
Copy link
Member

lqd commented May 13, 2024

I believe this bisects to LLVM 18 from #120055 cc @nikic

@saethlin saethlin added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 13, 2024
@saethlin
Copy link
Member

We are hitting an LLVM assertion:

Assertion failed: (N < NumContainedTys && "Element number out of range!"), function getElementType, file DerivedTypes.h, line 343.

@saethlin saethlin added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label May 13, 2024
@nikic
Copy link
Contributor

nikic commented May 14, 2024

Could someone please run cargo -v and then repeat the rustc command with -C save-temps and share the bitcode files?

@DianQK
Copy link
Member

DianQK commented May 14, 2024

Could someone please run cargo -v and then repeat the rustc command with -C save-temps and share the bitcode files?

I can reproduce it, and I will try to reduce it.

@DianQK
Copy link
Member

DianQK commented May 14, 2024

Upstream issue: llvm/llvm-project#92062
Reduced: https://llvm.godbolt.org/z/a4h1abfKc.

target triple = "arm64"

@p = external global { {}, { ptr } }

define void @foo() {
bb:
  %i1 = load ptr, ptr @p, align 8
  store ptr %i1, ptr null, align 8
  ret void
}

@DianQK
Copy link
Member

DianQK commented May 16, 2024

It has already been backported to LLVM 18: llvm/llvm-project#92129.
@rustbot label +llvm-fixed-upstream

@rustbot rustbot added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes label May 16, 2024
@bors bors closed this as completed in 20483b6 May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants