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

Loop with break or continue at top level but not last statement fails validation #323

Closed
dkolsen-pgi opened this issue Nov 20, 2023 · 1 comment · Fixed by #611
Closed

Comments

@dkolsen-pgi
Copy link
Collaborator

dkolsen-pgi commented Nov 20, 2023

When a for, while, or do/while loop contains a break or continue statement at the top level of the loop's body, and the break or continue statement is not the last statement in the block, then ClangIR fails validation.

void test(int x) {
  for (int i = 0; i < x; ++i) {
    break;
    --x;
  }
}
loc("for-break.cpp":3:5): error: 'cir.yield' op must be the last operation in the parent block
fatal error: error in backend: CIR codegen: module verification error before running CIR passes

If the break or continue is in a nested scope within the loop (which is the normal case in real code), there is no error. If the break or continue statement is the last statement in the block then there is a different internal error which is covered by #324.

@bcardosolopes
Copy link
Member

Handling unreachable code is lacking some support here indeed. We should probably end the first basic block with cir.yield break, and start a new bb to stuff --x, which should end with a regular cir.yield.

bcardosolopes pushed a commit that referenced this issue Jun 6, 2024
Without this patch, CIR CodeGen continue to generate in the same block
after `cir.break` and `cir.continue`, which would cause verification
error because `cir.break` and `cir.continue` should appear at the end of
blocks.

This patch creates a new dangling block after generating `cir.break` and
`cir.continue` to fix the issue.

This will fix #323.
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 a pull request may close this issue.

2 participants