File tree 1 file changed +12
-3
lines changed 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -524,13 +524,22 @@ mlir::LogicalResult CIRGenFunction::buildReturnStmt(const ReturnStmt &S) {
524
524
else {
525
525
mlir::Location scopeLoc =
526
526
getLoc (RV ? RV->getSourceRange () : S.getSourceRange ());
527
+ // First create cir.scope and later emit it's body. Otherwise all CIRGen
528
+ // dispatched by `handleReturnVal()` might needs to manipulate blocks and
529
+ // look into parents, which are all unlinked.
530
+ mlir::OpBuilder::InsertPoint scopeBody;
527
531
builder.create <mlir::cir::ScopeOp>(
528
532
scopeLoc, /* scopeBuilder=*/
529
533
[&](mlir::OpBuilder &b, mlir::Location loc) {
530
- CIRGenFunction::LexicalScope lexScope{*this , loc,
531
- builder.getInsertionBlock ()};
532
- handleReturnVal ();
534
+ scopeBody = b.saveInsertionPoint ();
533
535
});
536
+ {
537
+ mlir::OpBuilder::InsertionGuard guard (builder);
538
+ builder.restoreInsertionPoint (scopeBody);
539
+ CIRGenFunction::LexicalScope lexScope{*this , scopeLoc,
540
+ builder.getInsertionBlock ()};
541
+ handleReturnVal ();
542
+ }
534
543
}
535
544
536
545
// Create a new return block (if not existent) and add a branch to
You can’t perform that action at this time.
0 commit comments