Skip to content

Commit

Permalink
[CIR][CIRGen][NFC] Split cir.scope creation on buildReturnStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardosolopes committed Sep 27, 2024
1 parent b0c1490 commit 37397b3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,22 @@ mlir::LogicalResult CIRGenFunction::buildReturnStmt(const ReturnStmt &S) {
else {
mlir::Location scopeLoc =
getLoc(RV ? RV->getSourceRange() : S.getSourceRange());
// First create cir.scope and later emit it's body. Otherwise all CIRGen
// dispatched by `handleReturnVal()` might needs to manipulate blocks and
// look into parents, which are all unlinked.
mlir::OpBuilder::InsertPoint scopeBody;
builder.create<mlir::cir::ScopeOp>(
scopeLoc, /*scopeBuilder=*/
[&](mlir::OpBuilder &b, mlir::Location loc) {
CIRGenFunction::LexicalScope lexScope{*this, loc,
builder.getInsertionBlock()};
handleReturnVal();
scopeBody = b.saveInsertionPoint();
});
{
mlir::OpBuilder::InsertionGuard guard(builder);
builder.restoreInsertionPoint(scopeBody);
CIRGenFunction::LexicalScope lexScope{*this, scopeLoc,
builder.getInsertionBlock()};
handleReturnVal();
}
}

// Create a new return block (if not existent) and add a branch to
Expand Down

0 comments on commit 37397b3

Please sign in to comment.