-
Notifications
You must be signed in to change notification settings - Fork 100
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
[CIR][CIRGen] Create a new block after break and continue #611
[CIR][CIRGen] Create a new block after break and continue #611
Conversation
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.
mlir::Block *currBlock = builder.getBlock(); | ||
mlir::Block *gotoBlock = currBlock; | ||
if (!currBlock->empty() && | ||
currBlock->back().hasTrait<mlir::OpTrait::IsTerminator>()) { | ||
gotoBlock = builder.createBlock(builder.getBlock()->getParent()); | ||
builder.setInsertionPointToEnd(gotoBlock); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of code was used for test shouldCreateBlkForGoto
in clang/test/CIR/CodeGen/goto.cpp
. However, it is unrelated to goto
, but a workaround for the broken code for break
. This patch also moves the test to switch.cpp
and renamed it to unreachable_after_break_1
.
@@ -0,0 +1,22 @@ | |||
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | |||
// RUN: FileCheck --input-file=%t.cir %s | |||
// XFAIL: * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are failing because the insertion point is restored by an InsertionGuard in buildSwitchBody()
. I suggest revising that part after #528 is merged to avoid conflict.
clangir/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Lines 972 to 978 in 3da10fa
} else if (lastCaseBlock) { | |
// This means it's a random stmt following up a case, just | |
// emit it as part of previous known case. | |
mlir::OpBuilder::InsertionGuard guardCase(builder); | |
builder.setInsertionPointToEnd(lastCaseBlock); | |
res = buildStmt(c, /*useCurrentScope=*/!isa<CompoundStmt>(c)); | |
} else { |
I'm going to resume reviewing this, sorry for the delay! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for your patience.
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 llvm#323.
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 llvm#323.
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 llvm#323.
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 llvm#323.
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.
Without this patch, CIR CodeGen continue to generate in the same block after
cir.break
andcir.continue
, which would cause verification error becausecir.break
andcir.continue
should appear at the end of blocks.This patch creates a new dangling block after generating
cir.break
andcir.continue
to fix the issue.This will fix #323.