Skip to content

rustc does not detect incorrect (generic) enum structure and overflow its stack instead #100618

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

Closed
aurantiaco-sucus opened this issue Aug 16, 2022 · 4 comments · Fixed by #138599
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test.

Comments

@aurantiaco-sucus
Copy link

I tried this code:

enum Foo<T: 'static> {
    Value(T),
    Recursive(&'static Foo<Option<T>>),
}

fn main() {
    let _x = Foo::Value(());
}

I expected to see this happen: rustc refuses to compile this enum and tell me this (definition) does not work

Instead, this happened: rustc overflows its stack and the compile process ends abruptly

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (40336865f 2022-08-15)
binary: rustc
commit-hash: 40336865fe7d4a01139a3336639c6971647e885c
commit-date: 2022-08-15
host: x86_64-pc-windows-msvc
release: 1.65.0-nightly
LLVM version: 15.0.0
Backtrace

thread 'rustc' has overflowed its stack
warning: `whlist` (bin "whlist") generated 9 warnings
error: could not compile `whlist`; 9 warnings emitted

Caused by:
  process didn't exit successfully: `rustc --crate-name whlist --edition=2021 src\main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=0d4447f233920318 --out-dir C:\Users\raida\CLionProjects\whlist\target\debug\deps -C incremental=C:\Users\raida\CLionProjects\whlist\target\debug\incremental -L dependency=C:\Users\raida\CLionProjects\whlist\target\debug\deps` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

@aurantiaco-sucus aurantiaco-sucus added the C-bug Category: This is a bug. label Aug 16, 2022
@aurantiaco-sucus
Copy link
Author

Formerly discussed here.

@steffahn
Copy link
Member

steffahn commented Aug 16, 2022

@rustbot label I-crash
@rustbot label A-codegen. (presumably)

Trying to reproduce on Godbolt’s Compiler Explorer, I noticed that the crash only happens if -C debuginfo=2 is provided to rustc.

@rustbot rustbot added the I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Aug 16, 2022
@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2022

Error: Parsing relabel command in comment failed: ...' A-codegen' | error: a label delta at >| ' (presumab'...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@rustbot rustbot added the A-codegen Area: Code generation label Aug 16, 2022
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 19, 2024
@aurantiaco-sucus
Copy link
Author

Just tested it again. It still happens with this version of toolchain:
rustc 1.84.0-nightly (03ee48451 2024-11-18)

@bors bors closed this as completed in 68b439c Apr 18, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 18, 2025
Rollup merge of rust-lang#138599 - adwinwhite:recursive-overflow, r=wesleywiser

avoid overflow when generating debuginfo for expanding recursive types

Fixes rust-lang#135093
Fixes rust-lang#121538
Fixes rust-lang#107362
Fixes rust-lang#100618
Fixes rust-lang#115994

The overflow happens because expanding recursive types keep creating new nested types when recurring into sub fields.
I fixed that by returning an empty stub node when expanding recursion is detected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants