Skip to content

rustc 1.78.0 segfault on MacOS / M1 #125053

Description

@dwrensha

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.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 12, 2024
  2. dwrensha commented on May 12, 2024

    @dwrensha
    ContributorAuthor

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

    [profile.dev]
    incremental = false
  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-incr-compArea: Incremental compilation
    O-macosOperating system: macOS
    on May 13, 2024
  4. lqd commented on May 13, 2024

    @lqd
    Member

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

  5. added
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    C-bugCategory: This is a bug.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 13, 2024
  6. saethlin commented on May 13, 2024

    @saethlin
    Member

    We are hitting an LLVM assertion:

    Assertion failed: (N < NumContainedTys && "Element number out of range!"), function getElementType, file DerivedTypes.h, line 343.
    
  7. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on May 13, 2024
  8. nikic commented on May 14, 2024

    @nikic
    Contributor

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

  9. dianqk commented on May 14, 2024

    @dianqk
    Member

    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.

  10. dianqk commented on May 14, 2024

    @dianqk
    Member

    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
    }
  11. dianqk commented on May 16, 2024

    @dianqk
    Member

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

  12. added
    llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
    on May 16, 2024
  13. added a commit that references this issue on May 20, 2024
    20483b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-macosOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions