Skip to content

Fix loop label placement in WhileLoopExpr lowering#4522

Draft
Islam-Imad wants to merge 1 commit intoRust-GCC:masterfrom
Islam-Imad:fix/while-loop-label-break
Draft

Fix loop label placement in WhileLoopExpr lowering#4522
Islam-Imad wants to merge 1 commit intoRust-GCC:masterfrom
Islam-Imad:fix/while-loop-label-break

Conversation

@Islam-Imad
Copy link
Copy Markdown
Contributor

@Islam-Imad Islam-Imad commented Apr 12, 2026

the loop label was placed early in the context and its should be added after the end of the loop.
closes #4521

the loop label was placed early in the context and its should be added
after the end of the loop.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Fix while label place.

gcc/testsuite/ChangeLog:

	* rust/execute/while-label-break.rs: New test.

Signed-off-by: Islam-Imad <islamimad404@gmail.com>
@Islam-Imad
Copy link
Copy Markdown
Contributor Author

cc @powerboat9

res += i;
i += 1;
if res + i >= 99 {
break 'calculation;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does continue 'calculation work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think because the label now after the loop.
i will check it then ping u for review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its impossible to create a single label for both continue and break. we have to create two labels one at the start and one at the end. right now i am hacking gcc/go to see how this problem is solved and yeah there is separation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will require more work to be done since we need to modify [loop,while,continue,break] and a lot of testing also. once its ready i will make it open again.

@Islam-Imad Islam-Imad marked this pull request as draft April 13, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[backend] bad gimple output in HIR::WhileLoopExpr

2 participants