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 crashes with SIGSEGV when compiling a 1000 nested inline const blocks. #138547

Open
aleksanderkrauze opened this issue Mar 15, 2025 · 2 comments
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aleksanderkrauze
Copy link

I have generated input file containing a 1000 nested inline const blocks with following python script:

def main():
    with open("silly.rs", "w") as file:
        n = 1000
        file.write("const _: () = ")
        for _ in range(0, n):
            file.write("const { ")

        for _ in range(0, n):
            file.write("} ")

        file.write(";\n")


if __name__ == "__main__":
    main()

Then called rustc:

rustc --crate-type=lib silly.rs

Which crashes with a SIGSEGV (backtrace below).

I expected to see this happen:

I don't know really. I was just being silly and wanted to see what would happen. I know that this is an unreasonable rust code, and I was prepared for some compiler error. However seeing not even an ICE, but a full compiler crash surprised me. Setting $RUST_MIN_STACK to suggested value helps, but still this seems to be some form of a compiler bug.

I quickly searched for relevant issues, but I have not found anything similar. I have now idea if and how this should be fixed, but I thought that at least I can report it.

Meta

rustc --version --verbose:

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7
Backtrace

$ rustc --crate-type=lib silly.rs
error: rustc interrupted by SIGSEGV, printing backtrace

/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x36705c3) [0x7221174705c3]
/usr/lib/libc.so.6(+0x3dcd0) [0x722113c4bcd0]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc(+0x1475a) [0x56e2f7f6875a]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0xf4) [0x7221193a157a]

### cycle encountered after 4 frames with period 7
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser15parse_full_stmt+0x41) [0x72211939f301]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x559bb5b) [0x72211939bb5b]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x5e73f81) [0x722119c73f81]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x5560ad2) [0x722119360ad2]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x55516b1) [0x7221193516b1]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4exprNtB4_6Parser21parse_expr_assoc_with+0x53) [0x72211935521f]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x2b66) [0x7221193a3fec]
### 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
zsh: segmentation fault (core dumped)  rustc --crate-type=lib silly.rs

@aleksanderkrauze aleksanderkrauze added the C-bug Category: This is a bug. label Mar 15, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 15, 2025
@jieyouxu jieyouxu added A-parser Area: The parsing of Rust source code to an AST I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 16, 2025
@Noratrieb Noratrieb added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. and removed I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Mar 16, 2025
@Noratrieb
Copy link
Member

Thank you for reporting the issue, but yeah, it's a stackoverflow on, well, that input :D. It can probably be fixed by adding some more stacker in places, but it is not exactly the most important issue :D.

@Noratrieb Noratrieb added the P-low Low priority label Mar 16, 2025
@matthiaskrgr
Copy link
Member

might be duplicate of #79766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants