rust-lang / rust-lang/rust

[ICE]: trying to emulate goto statements with blocks and labels crashes the parser

Open
#160,759 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code

not very minimal, and yes auto generated code

Meta

it does exist in both nightly and stable

rustc --version --verbose:

rustc --version --verbose
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 22.1.6
Error output
error: rustc interrupted by SIGSEGV, printing backtrace

/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x3e43a7c) [0x7efe20443a7c]
/usr/lib/libc.so.6(+0x3e6f0) [0x7efe1c23e6f0]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x578cee1) [0x7efe21d8cee1]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(_RNvMNtNtCskXCWpRIXswg_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x6b5) [0x7efe21d047bd]

### cycle encountered after 4 frames with period 7
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x56fd1fe) [0x7efe21cfd1fe]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x620868d) [0x7efe2280868d]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x6641b1c) [0x7efe22c41b1c]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x575b889) [0x7efe21d5b889]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(+0x574616d) [0x7efe21d4616d]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(_RNvMNtNtCskXCWpRIXswg_11rustc_parse6parser4exprNtB4_6Parser21parse_expr_assoc_with+0x45) [0x7efe21d4e8c5]
/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-6b1d913cde17a464.so(_RNvMNtNtCskXCWpRIXswg_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x7a7) [0x7efe21d048af]
### recursed 36 times


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
error: could not compile `testing-prefix-sum` (bin "testing-prefix-sum")

Caused by:
  process didn't exit successfully: `/home/vrtgs/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name testing_prefix_sum --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=168 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=5f9076c8e9dc112e --out-dir /media/MidSpeedDrive/Coding/testing/Rust/testing-prefix-sum/target/debug/build/testing-prefix-sum/ed1e5f75d90a5397/out -C incremental=/media/MidSpeedDrive/Coding/testing/Rust/testing-prefix-sum/target/debug/incremental -L dependency=/media/MidSpeedDrive/Coding/testing/Rust/testing-prefix-sum/target/debug/build/bitmatch/fc0c3334d8828c50/out --extern bitmatch=/media/MidSpeedDrive/Coding/testing/Rust/testing-prefix-sum/target/debug/build/bitmatch/fc0c3334d8828c50/out/libbitmatch-fc0c3334d8828c50.so` (signal: 11, SIGSEGV: invalid memory reference)
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x3c7cedc) [0x7f029167cedc]
/usr/lib/libc.so.6(+0x3e6f0) [0x7f028d63e6f0]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x577912d) [0x7f029317912d]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(_RNvMNtNtCsfK5nGUKPhFU_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x674) [0x7f02931a63f8]

### cycle encountered after 4 frames with period 7
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x57ae1b5) [0x7f02931ae1b5]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x578a6d1) [0x7f029318a6d1]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x64695c1) [0x7f0293e695c1]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x580b05b) [0x7f029320b05b]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(+0x57f7bab) [0x7f02931f7bab]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(_RNvMNtNtCsfK5nGUKPhFU_11rustc_parse6parser4exprNtB4_6Parser21parse_expr_assoc_with+0x45) [0x7f02931ff007]
/home/vrtgs/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-832cf6cfb1386559.so(_RNvMNtNtCsfK5nGUKPhFU_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x75a) [0x7f02931a64de]
### recursed 36 times

Notes

this is very useful, I am making an arm emulator, and the instruction decoder has terrible codegen if I break out each label to its own function, and the compiler also refuses to TCO because the instruction enum is pretty big, but with this I get a sizable speedup (measured by increasing the rust stack to RUST_MIN_STACK=167772160)

Workarounds

changing the stack size of rustc in build.rs

println!("cargo:rustc-env=RUST_MIN_STACK={}", 256_usize * 1024 * 1024);

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 with the linked generated example and reproduce it on stable and nightly, then trace the backtrace through rustc_parse::Parser::parse_stmt_without_recovery and parse_expr_assoc_with. Compare the block and label syntax in src/main.rs with the parser recursion; done means the reproduction no longer causes rustc to overflow its stack and crash.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.