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

Thread 'rustc' panicked at 'Stack should be empty: final_buf=FrameData...' #81920

Closed
ZhangZhuoSJTU opened this issue Feb 9, 2021 · 9 comments · Fixed by #100250
Closed

Thread 'rustc' panicked at 'Stack should be empty: final_buf=FrameData...' #81920

ZhangZhuoSJTU opened this issue Feb 9, 2021 · 9 comments · Fixed by #100250
Assignees
Labels
A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ZhangZhuoSJTU
Copy link

When I am studying the related in #81886, I found another ICE. Although I haven't figured out the root cause, I suspect they can be fixed together.

Code

#[a]

fn e() {
    #![r=#[l"")""

playground

Meta

It can be reproduced by nightly and beta versions.

rustc --version --verbose:

rustc 1.52.0-nightly (0fc6756b4 2021-02-08)
binary: rustc
commit-hash: 0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a
commit-date: 2021-02-08
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

rustc 1.50.0-beta.9 (2efd07024 2021-02-06)
binary: rustc
commit-hash: 2efd07024a6d1dc0d4ea0a538ddbcec7cc3a4eeb
commit-date: 2021-02-06
host: x86_64-unknown-linux-gnu
release: 1.50.0-beta.9

Error output

➜  playground rustc poc.rs
error: this file contains an unclosed delimiter
 --> poc.rs:4:19
  |
3 | fn e() {
  |        - unclosed delimiter
4 |     #![r=#[l"")""
  |       -           ^
  |       |
  |       unclosed delimiter

error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `""`
 --> poc.rs:4:13
  |
4 |     #![r=#[l"")""
  |           - -^
  |           | |
  |           | help: `]` may belong here
  |           unclosed delimiter

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `]`
 --> poc.rs:4:19
  |
3 | fn e() {
  |        - unclosed delimiter
4 |     #![r=#[l"")""
  |                  -^ expected one of `.`, `;`, `?`, `}`, or an operator
  |                  |
  |                  help: `}` may belong here

error[E0658]: attributes on expressions are experimental
 --> poc.rs:4:10
  |
4 |     #![r=#[l"")""
  |          ^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable

error: cannot find attribute `a` in this scope
 --> poc.rs:1:3
  |
1 | #[a]
  |   ^

error: cannot find attribute `r` in this scope
 --> poc.rs:4:8
  |
4 |     #![r=#[l"")""
  |        ^

error: cannot find attribute `l` in this scope
 --> poc.rs:4:12
  |
4 |     #![r=#[l"")""
  |            ^

thread 'rustc' panicked at 'Stack should be empty: final_buf=FrameData { open: poc.rs:4:11: 4:12 (#0), inner: [(Token(Token { kind: Ident("l", false), span: poc.rs:4:12: 4:13 (#0) }), Alone)] } stack=[FrameData { open: poc.rs:1:1: 1:1 (#0), inner: [(Token(Token { kind: Pound, span: poc.rs:4:10: 4:11 (#0) }), Alone)] }]', compiler/rustc_parse/src/parser/mod.rs:1409:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (0fc6756b4 2021-02-08) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0658`.
Backtrace

thread 'rustc' panicked at 'Stack should be empty: final_buf=FrameData { open: poc.rs:4:11: 4:12 (#0), inner: [(Token(Token { kind: Ident("l", false), span: poc.rs:4:12: 4:13 (#0) }), Alone)] } stack=[FrameData { open: poc.rs:1:1: 1:1 (#0), inner: [(Token(Token { kind: Pound, span: poc.rs:4:10: 4:11 (#0) }), Alone)] }]', compiler/rustc_parse/src/parser/mod.rs:1409:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a/library/std/src/panicking.rs:435:5
   2: <rustc_parse::parser::Parser::collect_tokens_trailing_token::LazyTokenStreamImpl as rustc_ast::tokenstream::CreateTokenStream>::create_token_stream
   3: rustc_parse::prepend_attrs
   4: rustc_parse::nt_to_tokenstream
   5: rustc_ast_lowering::TokenStreamLowering::lower_token
   6: rustc_ast_lowering::LoweringContext::lower_mac_args
   7: rustc_ast_lowering::LoweringContext::lower_attr
   8: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   9: rustc_ast_lowering::LoweringContext::lower_attrs
  10: rustc_ast_lowering::item::<impl rustc_ast_lowering::LoweringContext>::lower_item
  11: rustc_ast_lowering::LoweringContext::with_hir_id_owner
  12: <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_mod
  13: rustc_ast_lowering::lower_crate
  14: rustc_interface::passes::BoxedResolver::access::{{closure}}
  15: rustc_interface::passes::configure_and_expand::{{closure}}
  16: rustc_interface::passes::BoxedResolver::access
  17: rustc_interface::queries::Queries::lower_to_hir
  18: rustc_interface::queries::Queries::global_ctxt
  19: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  20: rustc_span::with_source_map
  21: rustc_interface::interface::create_compiler_and_run
  22: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@ZhangZhuoSJTU ZhangZhuoSJTU 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 Feb 9, 2021
@jonas-schievink jonas-schievink added A-parser Area: The parsing of Rust source code to an AST. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 9, 2021
@apiraino apiraino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 10, 2021
@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@apiraino
Copy link
Contributor

I wonder if this is close enough to #81886 and #81845 to be considered duplicate

@Aaron1011
Copy link
Member

This issue is unrelated to either of those

@Aaron1011 Aaron1011 self-assigned this Feb 20, 2021
@Aaron1011
Copy link
Member

I don't think this is P-Medium - it only occurs with a strange input, and then only after errors have already been emitted.

@apiraino
Copy link
Contributor

ok thanks @Aaron1011 I'll downgrade to p-low

@rustbot label +P-low -P-medium

@rustbot rustbot added P-low Low priority and removed P-medium Medium priority labels Feb 24, 2021
@Badel2
Copy link
Contributor

Badel2 commented Nov 9, 2021

I found a similar ICE using fuzz-rustc

#![x=(y[(;z[);
thread 'rustc' panicked at 'Stack should be empty: final_buf=FrameData { open: src/main.rs:1:8: 1:9 (#0), open_delim: Bracket, inner: [(Delimited(DelimSpan { open: src/main.rs:1:9: 1:10 (#0), close: src/main.rs:1:13: 1:14 (#0) }, Paren, AttrAnnotatedTokenStream([(Token(Token { kind: Semi, span: src/main.rs:1:10: 1:11 (#0) }), Alone), (Token(Token { kind: Ident("z", false), span: src/main.rs:1:11: 1:12 (#0) }), Alone), (Delimited(DelimSpan { open: src/main.rs:1:12: 1:13 (#0), close: src/main.rs:1:13: 1:14 (#0) }, Bracket, AttrAnnotatedTokenStream([])), Alone)])), Alone)] } stack=[FrameData { open: no-location (#0), open_delim: NoDelim, inner: [] }, FrameData { open: src/main.rs:1:6: 1:7 (#0), open_delim: Paren, inner: [(Token(Token { kind: Ident("y", false), span: src/main.rs:1:7: 1:8 (#0) }), Alone)] }]', compiler/rustc_parse/src/parser/attr_wrapper.rs:501:5

See also #87793

@hellow554
Copy link
Contributor

A user in #96818 get's ICE with valid code and I think it's the same underlying problem.

macro_rules! values {
	($($token:ident($value:literal) $(as $inner:ty)? => $attr:meta,)*) => {
		#[derive(Debug)]
		pub enum TokenKind {
			$(
				#[$attr]
				$token $($inner)? = $value,
			)*
		}
	};
}

values!(STRING(1) as (String) => cfg(test),);

Should this issue be bumped to P-medium?

@Aaron1011
Copy link
Member

All of the ICEs only occur after an error is emitted. However, I'll start working on a fix

@matthiaskrgr
Copy link
Member

@Aaron1011 any updates? 🙃

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 20, 2022
…aron1011

Manually cleanup token stream when macro expansion aborts.

In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE.

In this case, this PR manually cleans up the token stream by closing all currently open delimiters.

Fixes rust-lang#96818.
Fixes rust-lang#80447.
Fixes rust-lang#81920.
Fixes rust-lang#91023.
@bors bors closed this as completed in 14b27cf Sep 20, 2022
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
Manually cleanup token stream when macro expansion aborts.

In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE.

In this case, this PR manually cleans up the token stream by closing all currently open delimiters.

Fixes rust-lang/rust#96818.
Fixes rust-lang/rust#80447.
Fixes rust-lang/rust#81920.
Fixes rust-lang/rust#91023.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
Manually cleanup token stream when macro expansion aborts.

In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE.

In this case, this PR manually cleans up the token stream by closing all currently open delimiters.

Fixes rust-lang/rust#96818.
Fixes rust-lang/rust#80447.
Fixes rust-lang/rust#81920.
Fixes rust-lang/rust#91023.
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-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority 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.

8 participants