gccrs: Run block cleanup for unlabeled break and continue - #4710
Open
Lishin1215 wants to merge 1 commit into
Open
gccrs: Run block cleanup for unlabeled break and continue#4710Lishin1215 wants to merge 1 commit into
Lishin1215 wants to merge 1 commit into
Conversation
Lishin1215
force-pushed
the
drop-unlabeled-break-continue
branch
from
July 16, 2026 13:03
a503c0a to
487ed1d
Compare
Lishin1215
commented
Jul 16, 2026
| expr.get_locus ()); | ||
| ctx->add_statement (assignment); | ||
| } | ||
| else if (compiled_expr != nullptr && is_control_flow_expr (final_expr) |
Contributor
Author
There was a problem hiding this comment.
This handles tail-position control flow like { break } and { continue }.
The generated jump still needs to be added to the block body, otherwise it is
created but never emitted into the final block.
Make unlabeled break return its translated tree, matching continue. Emit tail-position break and continue expressions as statements so they stay inside the TRY_FINALLY_EXPR body and run block cleanup. gcc/rust/ChangeLog: * backend/rust-compile-block.cc (is_control_flow_expr): New helper. (CompileBlock::visit): Emit tail-position break and continue expressions as statements. * backend/rust-compile-expr.cc (CompileExpr::visit): Return the translated expression for unlabeled break instead of emitting it directly. gcc/testsuite/ChangeLog: * rust/execute/drop-unlabeled-break-continue.rs: New test. Signed-off-by: Lishin <lishin1008@gmail.com>
Lishin1215
force-pushed
the
drop-unlabeled-break-continue
branch
from
July 21, 2026 16:36
487ed1d to
c1150be
Compare
Contributor
Author
|
I also opened an issue for the double-drop case I mentioned in the PR description: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on the existing
HIR::BlockExprTRY_FINALLY_EXPRcleanup infrastructure.It keeps unlabeled
breakandcontinueinside the block body, so block cleanupcan run when they leave scopes.
It covers these unlabeled cases:
continuecontinuebreakbreakbreakwith a valueThe tests use
loopinstead ofwhileto keep the coverage focused on cleanup behavior.Follow-up work:
break/continuereturncleanupWhile testing this change, I also found a separate issue that should be
tracked outside this PR:
drop/initialized flags.