Skip to content

rustc unexpectedly overflowed its stack! (Nested Datatypes) #115994

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
cutthroat opened this issue Sep 20, 2023 · 1 comment · Fixed by #138599
Closed

rustc unexpectedly overflowed its stack! (Nested Datatypes) #115994

cutthroat opened this issue Sep 20, 2023 · 1 comment · Fixed by #138599
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cutthroat
Copy link

cutthroat commented Sep 20, 2023

Code

// To prevent "overflow while adding drop-check rules".
use std::mem::ManuallyDrop;

pub enum Foo<U> {
    Leaf(U),

    Branch(BoxedFoo<BoxedFoo<U>>),
}

pub type BoxedFoo<U> = ManuallyDrop<Box<Foo<U>>>;

pub fn test() -> Foo<usize> {
    todo!()
}

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (65ea825f4 2023-09-18)
binary: rustc
commit-hash: 65ea825f4021eaf77f1b25139969712d65b435a4
commit-date: 2023-09-18
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

Error output

error: rustc interrupted by SIGSEGV, printing backtrace
Backtrace

<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x3154476)[0x7fc55fbb1476]
/usr/lib/libc.so.6(+0x3e710)[0x7fc55c679710]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x14)[0x7fc55de39434]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(_RNvNtNtCsgKY0QmBZTTg_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x201)[0x7fc55de39621]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13d7aab)[0x7fc55de34aab]

### cycle encountered after 7 frames with period 8
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]
### recursed 31 times

<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8e42d501a7efdfb9.so(+0x13dde4c)[0x7fc55de3ae4c]

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
note: backtrace dumped due to SIGSEGV! resuming signal
error: could not compile `rustc-bug` (lib)

Caused by:
  process didn't exit successfully: `<redacted>/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name rustc_bug --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=190 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b16d58bd391752b1 -C extra-filename=-b16d58bd391752b1 --out-dir <redacted>/rustc-bug/target/debug/deps -C incremental=<redacted>/rustc-bug/target/debug/incremental -L dependency=<redacted>/rustc-bug/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)

Edit: Simplified.

@cutthroat cutthroat added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 20, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 20, 2023
@saethlin saethlin added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 20, 2023
@clubby789
Copy link
Contributor

clubby789 commented Sep 22, 2023

This requires -Cdebuginfo=2 to reproduce without Cargo, otherwise it compiles normally. Seems like it's recursing forever here

pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &mut String) {
let def_key = tcx.def_key(def_id);
if qualified {
if let Some(parent) = def_key.parent {
push_item_name(tcx, DefId { krate: def_id.krate, index: parent }, true, output);

My mistake, the recursion is in push_generic_params_internal. On my system at least, the small recursion in push_item_name is just what pushes it over the limit.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 20, 2024
@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-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants