Add codegen support for goto#163
Merged
Merged
Conversation
Contributor
Author
|
One other thing worth mentioning: initially I considered not hoisting the variables at the beginning of the functionin the codegen. Instead I tried to emit the variables as they were declared in the program, and let goto_block do the hoisting inside the macro, however this turned out to be a bit more complicated because I needed to duplicate the GetDefaultAsString logic inside libcc2rs-macro. |
Contributor
|
What happens with VLAs declare inside goto? |
Contributor
Author
I did not think about that. We don't currently translate VLAs so I skipped this case. Should we add support for that in this PR or do we leave it for later? |
lucic71
added a commit
to lucic71/cpp2rust
that referenced
this pull request
Jun 4, 2026
Depends on Cpp2Rust#161. See Cpp2Rust#161 for a more detailed description of how goto is implemented. On the codegen part, this PR emits the goto_block and goto macros when it hits functions that use labels and gotos internally. It also hoists local variables at the start of the function so that all goto_block arms can see and use the local variables.
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.
Depends on #161. See #161 for a more detailed description of how goto is implemented.
On the codegen part, this PR emits the goto_block and goto macros when it hits functions that use labels and gotos internally. It also hoists local variables at the start of the function so that all goto_block arms can see and use the local variables.