rust-lang / rust-lang/rust

Stack overflow when compiling my project with opt-level>=2

Open
#154,063 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-crash needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

In this repo (extracted and reduced from a real codebase), running cargo build --release --bin distinct_three_fields_arcset fails with:

error: could not compile rustc-segv-repro (bin "distinct_three_fields_arcset")

Caused by:
process didn't exit successfully: rustc --crate-name distinct_three_fields_arcset --edition=2024 src/bin/distinct_three_fields_arcset.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=211 --crate-type bin --emit=dep-info,link -C opt-level=2 -C panic=abort -C lto=thin -C codegen-units=1 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=326a4eadd06de2c6 -C extra-filename=-49bdbdaccb93e839 --out-dir /path/to/rustc-segv-repro/target/release/deps -C strip=debuginfo -L dependency=/path/to/rustc-segv-repro/target/release/deps --extern ahash=/path/to/rustc-segv-repro/target/release/deps/libahash-6d969c81ab440607.rlib --extern dashmap=/path/to/rustc-segv-repro/target/release/deps/libdashmap-0778b1e0858bd4a4.rlib (signal: 11, SIGSEGV: invalid memory reference)

Setting a higher RUST_MIN_STACK makes the build succeed, so I don't know if this is a bug or just running out of a limited resource. Setting opt-level = 1 makes the build succeed.

In the real codebase, the error includes the following message, hence this bug report:

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
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

rustc --version --verbose:

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

I cannot easily try with latest Rust or nightly.

No backtrace is printed with RUST_BACKTRACE=1 in the linked repo. In the real codebase (which I cannot share) I get the following backtrace:

/usr/local/bin/../lib/librustc_driver-890dfd19c9b338c0.so(+0x3c83a9f)[0x7514a9c83a9f]
/lib/x86_64-linux-gnu/libc.so.6(+0x45330)[0x7514a5c45330]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution19getConstantMultipleEPKNS_4SCEVE+0x11c)[0x7514a439afdc]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution11getRangeRefEPKNS_4SCEVENS0_13RangeSignHintEj+0x1f9)[0x7514a40ebb13]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution11getRangeRefEPKNS_4SCEVENS0_13RangeSignHintEj+0x3d69)[0x7514a40ef683]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution21getZeroExtendExprImplEPKNS_4SCEVEPNS_4TypeEj+0x12ed)[0x7514a42046ed]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x22ab)[0x7514a44a96ab]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x332)[0x7514a3e09ff4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution28computeExitLimitFromCondImplERNS0_14ExitLimitCacheEPKNS_4LoopEPNS_5ValueEbbb+0x2a6)[0x7514a42e7a66]

### cycle encountered after 9 frames with period 16
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution30computeExitLimitFromCondCachedERNS0_14ExitLimitCacheEPKNS_4LoopEPNS_5ValueEbbb+0xaf)[0x7514a42e75bb]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution25computeBackedgeTakenCountEPKNS_4LoopEb+0x2de)[0x7514a42e86b0]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution11getRangeRefEPKNS_4SCEVENS0_13RangeSignHintEj+0x5047)[0x7514a40f0961]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10getAddExprERNS_15SmallVectorImplIPKNS_4SCEVEEENS2_11NoWrapFlagsEj+0xcff)[0x7514a421629d]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x713)[0x7514a44a7b13]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x332)[0x7514a3e09ff4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution27createNodeFromSelectLikePHIEPNS_7PHINodeE+0x325)[0x7514a421e665]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x29c)[0x7514a44a769c]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x332)[0x7514a3e09ff4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution27createNodeFromSelectLikePHIEPNS_7PHINodeE+0x247)[0x7514a421e587]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x29c)[0x7514a44a769c]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x332)[0x7514a3e09ff4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10LoopGuards16collectFromBlockERS0_RS1_PKNS_10BasicBlockES6_RNS_15SmallPtrSetImplIS6_EEj+0x1956)[0x7514a40df3e4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution12howFarToZeroEPKNS_4SCEVEPKNS_4LoopEbb+0x18b)[0x7514a48aee4b]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution24computeExitLimitFromICmpEPKNS_4LoopENS_12CmpPredicateEPKNS_4SCEVES7_bb+0x417)[0x7514a42e5517]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution28computeExitLimitFromCondImplERNS0_14ExitLimitCacheEPKNS_4LoopEPNS_5ValueEbbb+0x2d9)[0x7514a42e7a99]
### recursed 15 times

/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution30computeExitLimitFromCondCachedERNS0_14ExitLimitCacheEPKNS_4LoopEPNS_5ValueEbbb+0xaf)[0x7514a42e75bb]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution25computeBackedgeTakenCountEPKNS_4LoopEb+0x2de)[0x7514a42e86b0]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution11getRangeRefEPKNS_4SCEVENS0_13RangeSignHintEj+0x5047)[0x7514a40f0961]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10getAddExprERNS_15SmallVectorImplIPKNS_4SCEVEEENS2_11NoWrapFlagsEj+0xcff)[0x7514a421629d]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x713)[0x7514a44a7b13]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x332)[0x7514a3e09ff4]
/usr/local/bin/../lib/../lib/libLLVM.so.20.1-rust-1.90.0-stable(_ZN4llvm15ScalarEvolution27createNodeFromSelectLikePHIEPNS_7PHINodeE+0x325)[0x7514a421e665]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by cloning the linked rustc-segv-repro repository and running cargo build --release --bin distinct_three_fields_arcset with opt-level 2, then compare with opt-level 1 and a higher RUST_MIN_STACK. Use the reported LLVM ScalarEvolution stack trace as the entry point; done means the reduced project no longer causes rustc to stack overflow or crash at the affected optimization level.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.