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

Fix exception stack lowering in finally handlers #36480

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

c42f
Copy link
Member

@c42f c42f commented Jun 30, 2020

When using return or break nested inside finally handlers,
exception stack lowering failed to pop exceptions from the stack
correctly:

  • For return, the exception stack was not popped at all. If done
    inside a loop this could eventually cause the runtime to run out of
    memory.
  • For break, the exception stack was popped too early, causing subtle
    inconsistency in intermediate finally handlers.

Fix these issues by storing the current exception token stack with the
current finally handler information and using it to pop the stack before
jumping into the finally block.

Fixes #34579

CC @KristofferC

@c42f c42f added compiler:lowering Syntax lowering (compiler front end, 2nd stage) bugfix This change fixes an existing bug backport 1.5 labels Jun 30, 2020
@c42f c42f added this to the 1.5 milestone Jun 30, 2020
@c42f c42f requested a review from JeffBezanson June 30, 2020 09:39
When using `return` or `break` nested inside `finally` handlers,
exception stack lowering failed to pop exceptions from the stack
correctly:

* For `return`, the exception stack was not popped at all. If done
  inside a loop this could eventually cause the runtime to run out of
  memory.
* For `break`, the exception stack was popped too early, causing subtle
  inconsistency in intermediate finally handlers.

Fix these issues by storing the current exception token stack with the
current finally handler information and using it to pop the stack before
jumping into the finally block.

Fixes #34579
@c42f c42f force-pushed the cjf/excstack-return-via-finally-fix branch from ad159c9 to 97e8486 Compare June 30, 2020 21:55
@c42f c42f merged commit 16ba0dd into master Jul 1, 2020
@c42f c42f deleted the cjf/excstack-return-via-finally-fix branch July 1, 2020 02:20
KristofferC pushed a commit that referenced this pull request Jul 8, 2020
When using `return` or `break` nested inside `finally` handlers,
exception stack lowering failed to pop exceptions from the stack
correctly:

* For `return`, the exception stack was not popped at all. If done
  inside a loop this could eventually cause the runtime to run out of
  memory.
* For `break`, the exception stack was popped too early, causing subtle
  inconsistency in intermediate finally handlers.

Fix these issues by storing the current exception token stack with the
current finally handler information and using it to pop the stack before
jumping into the finally block.

Fixes #34579

(cherry picked from commit 16ba0dd)
@KristofferC KristofferC mentioned this pull request Jul 8, 2020
13 tasks
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
When using `return` or `break` nested inside `finally` handlers,
exception stack lowering failed to pop exceptions from the stack
correctly:

* For `return`, the exception stack was not popped at all. If done
  inside a loop this could eventually cause the runtime to run out of
  memory.
* For `break`, the exception stack was popped too early, causing subtle
  inconsistency in intermediate finally handlers.

Fix these issues by storing the current exception token stack with the
current finally handler information and using it to pop the stack before
jumping into the finally block.

Fixes JuliaLang#34579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception stack not cleaned up after return inside of a catch handler with a finally clause
3 participants