Skip to content

SIGSEGV when compiling criterion benchmark with large const generic array #136739

Closed as duplicate of#94793
@cdellacqua

Description

@cdellacqua

Code

Reproduction code can be found here hang_or_crash.rs

The culprit seems to be this:

pub struct CustomSlice<T, const N: usize>(pub [T; N]);

in combination with criterion iter_batched, when using a very large const generic:

fn criterion_benchmark(c: &mut Criterion) {
    c.bench_function("Demo", |b| {
        b.iter_batched(
            || CustomSlice([0; 1_000_000]), // <-- here
            |test| {
                assert_eq!(test.0[10], 0);
            },
            criterion::BatchSize::NumIterations(1),
        );
    });
}

I tried this with criterion 0.4.0 and 0.5.1

Meta

rustc --version --verbose:

rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-unknown-linux-gnu
release: 1.84.1
LLVM version: 19.1.5

rustc +nightly --version --verbose:

rustc 1.86.0-nightly (942db6782 2025-02-06)
binary: rustc
commit-hash: 942db6782f4a28c55b0b75b38fd4394d0483390f
commit-date: 2025-02-06
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Error output

When running cargo +stable bench --profile=dev I get the following, but note that the issue is present even when specifying -Znext-solver and -Znext-solver=coherence.

error: could not compile `hang_or_crash` (bench "bench")

Caused by:
  process didn't exit successfully: `/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name bench --edition=2021 benches/bench.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=176 --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg test --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=334ac19c27aebb52 -C extra-filename=-334ac19c27aebb52 --out-dir /home/carlo/Dev/Personal/hang_or_crash.rs/target/debug/deps -C incremental=/home/carlo/Dev/Personal/hang_or_crash.rs/target/debug/incremental -L dependency=/home/carlo/Dev/Personal/hang_or_crash.rs/target/debug/deps --extern criterion=/home/carlo/Dev/Personal/hang_or_crash.rs/target/debug/deps/libcriterion-71a6c66f6e81fca7.rlib --extern hang_or_crash=/home/carlo/Dev/Personal/hang_or_crash.rs/target/debug/deps/libhang_or_crash-3710c6af0466eef1.rlib` (signal: 11, SIGSEGV: invalid memory reference)
Backtrace

error: rustc interrupted by SIGSEGV, printing backtrace

/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x3633e63) [0x7a4d56833e63]
/usr/lib/libc.so.6(+0x3d1d0) [0x7a4d5304c1d0]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm12SelectionDAG18ReplaceAllUsesWithEPNS_6SDNodeEPKNS_7SDValueE+0x1fb) [0x7a4d513b9a3b]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(+0x6c2a999) [0x7a4d51c2a999]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm12SelectionDAG7CombineENS_12CombineLevelEPNS_9AAResultsENS_15CodeGenOptLevelE+0xd8b) [0x7a4d5131555b]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm16SelectionDAGISel17CodeGenAndEmitDAGEv+0x6d) [0x7a4d5131852d]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x1ac4) [0x7a4d51405498]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0x11e) [0x7a4d513ebcde]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm22SelectionDAGISelLegacy20runOnMachineFunctionERNS_15MachineFunctionE+0x34e) [0x7a4d5127978e]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xcc1) [0x7a4d5127ea4d]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f) [0x7a4d5127dd0d]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.84.1-stable(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x2b9) [0x7a4d518fe54d]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(LLVMRustWriteOutputFile+0x171) [0x7a4d58bb8a31]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x59b867b) [0x7a4d58bb867b]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x59b91a0) [0x7a4d58bb91a0]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x59b8e28) [0x7a4d58bb8e28]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x5a81a5b) [0x7a4d58c81a5b]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x5a7ec9d) [0x7a4d58c7ec9d]
/home/carlo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-cbb5ad48aac6e327.so(+0x5a7efb9) [0x7a4d58c7efb9]
/usr/lib/libc.so.6(+0x942ce) [0x7a4d530a32ce]
/usr/lib/libc.so.6(+0x11929c) [0x7a4d5312829c]

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

Possibly related issues

#136282

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions