Skip to content

Preserve unlabelled break targets in nested control-flow macros - #581

Merged
nunoplopes merged 1 commit into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-0ypb55ds2b
Nov 2, 2026
Merged

nunoplopes merged 1 commit into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-0ypb55ds2b

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Unlabelled breaks inside nested control-flow macros now reach their intended targets rather than a generated loop. The rewriters inspect nested macro inputs before those inputs expand.

  • Reuse the nested-macro walker for goto jumps and exit rewriting.
  • Treat nested goto blocks as transparent, while each switch owns breaks in its arms.
  • Visit nested switch conditions and guards in the enclosing context.

Real user loops still stop propagation, and explicitly labelled exits are unchanged. Traversal recognizes macros named goto_block! and switch!, including qualified paths; other macro token bodies remain opaque.

Testing

tests/unit/goto_nested_loop_control.c checks nested labelled compounds in a user loop and in a fallthrough switch. The switch version checks that a break leaves the switch while later user-loop iterations still run. Lit compares native C with both translation models and checks their generated-source expectations.

The macro test runner reports 23 passed, no failures and no ignored tests, covering dispatch, fallthrough, goto jumps and the compile-fail harness. The existing Rust tests are unchanged.

Coverage is bounded; affected application prevalence remains unknown.

5 recorded checks pass with this change.

  • libcc2rs-macros unit, integration and compile-fail tests
  • libcc2rs-macros rustfmt
  • libcc2rs-macros clippy
  • Nested control-flow C fixture clang-format
  • Goto and switch lit tests in both translation models

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

@nunoplopes

Copy link
Copy Markdown
Contributor

@perfloop-agent Instead of having this complicated test in control_flow.rs, extend the C test (goto_nested_loop_control.c) to have a version with switch to cover the new code.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Tomás Senart <ts@perfloop.ai>
@perfloop
perfloop Bot force-pushed the perfloop-pr-open-0ypb55ds2b branch from db14023 to e870e35 Compare November 2, 2026 14:52
@perfloop-agent

Copy link
Copy Markdown
Contributor Author

I removed the added Rust tests and extended the C fixture with a switch version. It nests labelled compounds inside a fallthrough switch and checks that break leaves the switch while the user loop continues.

@nunoplopes
nunoplopes merged commit e8228f1 into Cpp2Rust:master Nov 2, 2026
9 checks passed
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.

2 participants