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 pop_exception lowering for try-break-finally (#31766) #31931

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3479,7 +3479,7 @@ f(x) = yt(x)
(label-map (table)) ;; maps label names to generated addresses
(label-nesting (table)) ;; exception handler and catch block nesting of each label
(finally-handler #f) ;; `(var label map level)` where `map` is a list of `(tag . action)`.
;; to exit the current finally block, set `var` to integer `tag`,
;; To exit the current finally block, set `var` to integer `tag`,
;; jump to `label`, and put `(tag . action)` in the map, where `action`
;; is `(return x)`, `(break x)`, or a call to rethrow.
(handler-goto-fixups '()) ;; `goto`s that might need `leave` exprs added
Expand Down Expand Up @@ -3542,11 +3542,11 @@ f(x) = yt(x)
(define (emit-break labl)
(let ((lvl (caddr labl))
(dest-tokens (cadddr labl)))
(let ((pexc (pop-exc-expr catch-token-stack dest-tokens)))
(if pexc (emit pexc)))
(if (and finally-handler (> (cadddr finally-handler) lvl))
(leave-finally-block `(break ,labl))
(begin
(let ((pexc (pop-exc-expr catch-token-stack dest-tokens)))
(if pexc (emit pexc)))
(if (> handler-level lvl)
(emit `(leave ,(- handler-level lvl))))
(emit `(goto ,(cadr labl)))))))
Expand Down
35 changes: 35 additions & 0 deletions test/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ end
end
end
test_exc_stack_catch_return()

for i=1:1
try
error("A")
Expand All @@ -91,21 +92,55 @@ end
break
end
end
# Also test try-break-finally forms here. See #31766
for i=1:1
try
error("A")
catch
@test length(catch_stack()) == 1
break
finally
@test length(catch_stack()) == 0
end
end
@test length(catch_stack()) == 0

for i=1:1
try
error("A")
catch
@test length(catch_stack()) == 1
continue
end
end
for i=1:1
try
error("A")
catch
@test length(catch_stack()) == 1
continue
finally
@test length(catch_stack()) == 0
end
end
@test length(catch_stack()) == 0

try
error("A")
catch
@test length(catch_stack()) == 1
@goto outofcatch
end
@label outofcatch
try
error("A")
catch
@test length(catch_stack()) == 1
@goto outofcatch2
finally
@test length(catch_stack()) == 0
end
@label outofcatch2
@test length(catch_stack()) == 0

# Exiting from a try block in various ways should not affect the exception
Expand Down