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 SIGSEGV on 1.82.0 and 1.84.0-nightly using anyhow and clap #133203

Closed
fence-sitter opened this issue Nov 19, 2024 · 4 comments · Fixed by #133799
Closed

rustc SIGSEGV on 1.82.0 and 1.84.0-nightly using anyhow and clap #133203

fence-sitter opened this issue Nov 19, 2024 · 4 comments · Fixed by #133799
Assignees
Labels
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fence-sitter
Copy link

Saw this in a larger codebase and tried to reduce the example as much as possible. It fails when running cargo build --release but compiles normally when running cargo build.

I noted that a lot of existing SIGSEGV issues were marked as C-defective-hardware, so I replicated the issue on three different machines to try and rule that out.

Code

Cargo.toml:

[package]
name = "rustc-sigsegv"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.93"
clap = { version = "4.5.21", features = ["derive"] }

main.rs:

use anyhow::Context;
use clap::Parser;

#[derive(clap::Parser)]
struct Args {
    option: Options,
}

fn main() -> anyhow::Result<std::convert::Infallible> {
    let args = Args::parse();

    loop {
        // rustc crashes if the error type is `anyhow::Error` or
        // `std::convert::Infallible`. rustc does not crash if the error type is
        // `std::io::Error`.
        Ok::<(), std::convert::Infallible>(())
            .context("")
            .or_else(match args.option {
                Options::A => Err,
                // Merging these match arms stops rustc from crashing.
                Options::B => |_| Ok(()),
                Options::C => |_| Ok(()),
            })?
    }
}

#[derive(Clone, Copy, clap::ValueEnum)]
enum Options {
    /// Deleting this doc comment stops rustc from crashing.
    A,
    B,
    C,
}

Meta

Fails on stable:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Also fails on nightly:

rustc 1.84.0-nightly (5ec7d6eee 2024-11-17)
binary: rustc
commit-hash: 5ec7d6eee7e0f5236ec1559499070eaf836bc608
commit-date: 2024-11-17
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Error output

error: rustc interrupted by SIGSEGV, printing backtrace
Backtrace

    Updating crates.io index
 Downloading crates ...
  Downloaded anstyle-query v1.1.2
  Downloaded is_terminal_polyfill v1.70.1
  Downloaded anstyle v1.0.10
  Downloaded heck v0.5.0
  Downloaded strsim v0.11.1
  Downloaded utf8parse v0.2.2
  Downloaded colorchoice v1.0.3
  Downloaded anstyle-parse v0.2.6
  Downloaded quote v1.0.37
  Downloaded proc-macro2 v1.0.89
  Downloaded anyhow v1.0.93
  Downloaded clap v4.5.21
  Downloaded unicode-ident v1.0.13
  Downloaded clap_derive v4.5.18
  Downloaded clap_lex v0.7.3
  Downloaded anstream v0.6.18
  Downloaded clap_builder v4.5.21
  Downloaded syn v2.0.87
   Compiling proc-macro2 v1.0.89
   Compiling unicode-ident v1.0.13
   Compiling utf8parse v0.2.2
   Compiling is_terminal_polyfill v1.70.1
   Compiling anstyle v1.0.10
   Compiling colorchoice v1.0.3
   Compiling anstyle-query v1.1.2
   Compiling clap_lex v0.7.3
   Compiling strsim v0.11.1
   Compiling heck v0.5.0
   Compiling anyhow v1.0.93
   Compiling anstyle-parse v0.2.6
   Compiling anstream v0.6.18
   Compiling clap_builder v4.5.21
   Compiling quote v1.0.37
   Compiling syn v2.0.87
   Compiling clap_derive v4.5.18
   Compiling clap v4.5.21
   Compiling rustc-sigsegv v0.1.0 (/)
error: rustc interrupted by SIGSEGV, printing backtrace

/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(+0x33b6d83)[0x7f18fb1b6d83]
/lib/x86_64-linux-gnu/libc.so.6(+0x3c050)[0x7f18f7c5b050]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm9MemorySSA23insertIntoListsForBlockEPNS_12MemoryAccessEPKNS_10BasicBlockENS0_14InsertionPlaceE+0x18d)[0x7f18f619341d]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x6f50465)[0x7f18f6d50465]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x63d72d1)[0x7f18f61d72d1]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x63d6be8)[0x7f18f61d6be8]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm11PassManagerINS_4LoopENS_15AnalysisManagerIS1_JRNS_27LoopStandardAnalysisResultsEEEEJS4_RNS_10LPMUpdaterEEE24runWithoutLoopNestPassesERS1_RS5_S4_S7_+0x4ac)[0x7f18f5f5e1c2]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x615dc2e)[0x7f18f5f5dc2e]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm25FunctionToLoopPassAdaptor3runERNS_8FunctionERNS_15AnalysisManagerIS1_JEEE+0x60b)[0x7f18f5e1ed0b]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x601e6df)[0x7f18f5e1e6df]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm11PassManagerINS_8FunctionENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0xb87)[0x7f18f5e1d061]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm26CGSCCToFunctionPassAdaptor3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x36a)[0x7f18f6041b2a]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x62417b5)[0x7f18f60417b5]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm11PassManagerINS_13LazyCallGraph3SCCENS_15AnalysisManagerIS2_JRS1_EEEJS4_RNS_17CGSCCUpdateResultEEE3runERS2_RS5_S4_S7_+0x94f)[0x7f18f604092d]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm21DevirtSCCRepeatedPass3runERNS_13LazyCallGraph3SCCERNS_15AnalysisManagerIS2_JRS1_EEES5_RNS_17CGSCCUpdateResultE+0x183)[0x7f18f603f4c3]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm33ModuleToPostOrderCGSCCPassAdaptor3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0xa03)[0x7f18f603e115]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x623d70d)[0x7f18f603d70d]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x229)[0x7f18f6585ea9]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm24ModuleInlinerWrapperPass3runERNS_6ModuleERNS_15AnalysisManagerIS1_JEEE+0x1a1)[0x7f18f6587761]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(+0x67875af)[0x7f18f65875af]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.82.0-stable(_ZN4llvm11PassManagerINS_6ModuleENS_15AnalysisManagerIS1_JEEEJEE3runERS1_RS3_+0x229)[0x7f18f6585ea9]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(LLVMRustOptimize+0x84c)[0x7f18fd5b6098]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(+0x57b7f2f)[0x7f18fd5b7f2f]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(_RNvXs1_Cs1oxnbOlTNyI_18rustc_codegen_llvmNtB5_18LlvmCodegenBackendNtNtNtCs6rvTwnzI2jg_17rustc_codegen_ssa6traits5write19WriteBackendMethods8optimize+0x135)[0x7f18fd67f6f5]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(+0x5878c58)[0x7f18fd678c58]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(+0x5878821)[0x7f18fd678821]
/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/lib/librustc_driver-2d2db9d3929202cf.so(+0x5877d2b)[0x7f18fd677d2b]
/lib/x86_64-linux-gnu/libc.so.6(+0x891c4)[0x7f18f7ca81c4]
/lib/x86_64-linux-gnu/libc.so.6(__clone+0x40)[0x7f18f7d27ac0]

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
note: backtrace dumped due to SIGSEGV! resuming signal
error: could not compile `rustc-sigsegv` (bin "rustc-sigsegv")

Caused by:
  process didn't exit successfully: `/usr/local/rustup/toolchains/1.82.0-x86_64-unknown-linux-gnu/bin/rustc --crate-name rustc_sigsegv --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=aba743abba83be16 -C extra-filename=-aba743abba83be16 --out-dir /target/release/deps -C strip=debuginfo -L dependency=/target/release/deps --extern anyhow=/target/release/deps/libanyhow-863377357f01da5a.rlib --extern clap=/target/release/deps/libclap-6f313dd98669d063.rlib` (signal: 11, SIGSEGV: invalid memory reference)

@fence-sitter fence-sitter added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 19, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 19, 2024
@bjorn3
Copy link
Member

bjorn3 commented Nov 19, 2024

This looks like it is either an LLVM bug or rustc producing invalid LLVM IR.

@bjorn3 bjorn3 added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Nov 19, 2024
@DianQK
Copy link
Member

DianQK commented Nov 19, 2024

Reduced: https://llvm.godbolt.org/z/hbTEMc7qs

@DianQK DianQK self-assigned this Nov 19, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 19, 2024
@DianQK
Copy link
Member

DianQK commented Nov 19, 2024

Upstream issue: llvm/llvm-project#116809
🌕💤️

@saethlin
Copy link
Member

I swear I posted this comment already. Huh.

I noted that a lot of existing SIGSEGV issues were marked as C-defective-hardware, so I replicated the issue on three different machines to try and rule that out.

The signature of defective hardware is getting different behavior build-to-build; sometimes the build succeeds, and when it crashes you get various different backtraces. If you always get exactly the same behavior, high chance it's a compiler bug of some sort.

@DianQK DianQK added the llvm-fixed-upstream Issue expected to be fixed by the next major LLVM upgrade, or backported fixes label Nov 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Update LLVM to 19.1.5

Fixes rust-lang#133276. Fixes rust-lang#133203.

r? nikic or wg-llvm
@bors bors closed this as completed in 96e51d9 Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 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.

5 participants