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

translate-c: support goto statements #19146

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

rpkak
Copy link

@rpkak rpkak commented Mar 2, 2024

Goto support works by creating a boolean variable per label, which is false by default. A goto changes this variable to true and breaks to the highest common scope of the goto and the label. Now, if and while statements, which are controlled by the boolean variable, jump over the execution part of the code to get to the label.

closes #11992

@rpkak rpkak force-pushed the translate-c-goto branch 2 times, most recently from d0bd7fd to 5a6574e Compare March 8, 2024 06:13
@rpkak rpkak force-pushed the translate-c-goto branch 3 times, most recently from 4509616 to 0e5b47c Compare March 14, 2024 20:33
@rpkak
Copy link
Author

rpkak commented Apr 4, 2024

I think I completed this PR now. It lacks the ability to use goto to jump out of or within a statement expression, but I don't think there is much need for this.
As I stated in a87c470 this PR also fixes #14809.
This PR inserts while loops which exist not as while loops in the c code. These loops have the same issues as descripted in #15155/#16790.

@rpkak rpkak marked this pull request as ready for review April 4, 2024 19:31
@mnemnion
Copy link

mnemnion commented May 1, 2024

Shouldn't a feature like this wait on #19812? That will be a more performant and general way to translate gotos into Zig, without adding extra conditionals to the code.

@rpkak
Copy link
Author

rpkak commented May 25, 2024

Shouldn't a feature like this wait on #19812? That will be a more performant and general way to translate gotos into Zig, without adding extra conditionals to the code.

@mnemnion I don't see how #19812 will make this more performant or general.
I have not seen any c code snippet, where llvm does not optimize away the goto-variable generated by this PR.

For the translation of c-switch statements, I argree. Translate-c outputs zig code multiple times, if the code is accessible by multiple cases. This PR makes translate-c also output case code once more, if the case is accessed by a goto. But this rewrite would be translate-c-switch specific and not translate-c-goto specific.

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.

translate-c: support goto
2 participants