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 runs out of memory when compiling an if statement with no block, enclosed in parentheses #61858

Closed
kuretchi opened this issue Jun 15, 2019 · 7 comments · Fixed by #62607
Assignees
Labels
C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kuretchi
Copy link

I tried this code:

fn main() {
    (if foobar)
}
$ ulimit -v 2000000  # 2 GB
$ rustc main.rs

rustc first outputs some error messages and then hangs up trying to allocate a large amount of memory.

error: expected `{`, found `)`
 --> main.rs:2:15
  |
2 |     (if foobar)
  |      --       ^ expected `{`
  |      |
  |      this `if` statement has a condition, but no block

error: expected expression, found `<eof>`
 --> main.rs:3:1
  |
3 | }
  | ^ expected expression

memory allocation of 1610612736 bytes failedAborted (core dumped)

Playground

Meta

rustc --version --verbose:

rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-unknown-linux-gnu
release: 1.35.0
LLVM version: 8.0
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated labels Jun 15, 2019
@tesuji

This comment has been minimized.

@rustbot

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Jun 15, 2019
@tesuji
Copy link
Contributor

tesuji commented Jun 18, 2019

Rust 1.34.0 and before is OK: https://godbolt.org/z/dFMxwR

@jonas-schievink jonas-schievink added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Jun 18, 2019
@pnkfelix
Copy link
Member

triage: P-medium. Removing nomination. Assigning to self and @estebank for initial investigation.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Jun 20, 2019
@dwrensha
Copy link
Contributor

I'm seeing the same behavior on the following programs:

pub fn m(<k<kn(m(nka[ nka[ (]k(

and

fn z() { loop { w& if ( if (r( loop { w if ( if (r

These were found with the help of libfuzzer-sys.

@dwrensha
Copy link
Contributor

Another program that I also observe to make rustc run out of memory:

fn a() -> i32 { let c c2( } fn b(x:[

@estebank
Copy link
Contributor

The original report is caused due to Parser::expected_tokens growing unbounded in a bad parser code path, in part due to it being a Vec and not a FxHashSet (which it can't be at the moment). Now that I have a clue at what causes the behavior, I'll dig deeper for the trigger.

Centril added a commit to Centril/rust that referenced this issue Jul 12, 2019
…, r=petrochenkov

Correctly break out of recovery loop

Fix rust-lang#61858.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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