================ @@ -289,6 +291,52 @@ void CIRGenItaniumCXXABI::emitDestructorCall( vttTy, nullptr); } +// The idea here is creating a separate block for the throw with an +// `UnreachableOp` as the terminator. So, we branch from the current block +// to the throw block and create a block for the remaining operations. +static void insertThrowAndSplit(mlir::OpBuilder &builder, mlir::Location loc, + mlir::Value exceptionPtr = {}, + mlir::FlatSymbolRefAttr typeInfo = {}, + mlir::FlatSymbolRefAttr dtor = {}) { + mlir::Block *currentBlock = builder.getInsertionBlock(); + mlir::Region *region = currentBlock->getParent(); + + if (currentBlock->empty()) { + cir::ThrowOp::create(builder, loc, exceptionPtr, typeInfo, dtor); + cir::UnreachableOp::create(builder, loc); + } else { + mlir::Block *throwBlock = builder.createBlock(region); + + cir::ThrowOp::create(builder, loc, exceptionPtr, typeInfo, dtor); + cir::UnreachableOp::create(builder, loc); + + builder.setInsertionPointToEnd(currentBlock); + cir::BrOp::create(builder, loc, throwBlock); + } + + (void)builder.createBlock(region); + + // This will be erased during codegen, it acts as a placeholder for the + // operations to be inserted (if any) ---------------- AmrDeveloper wrote:
That's right, it's more clear when I tested it with code after throw, Thanks https://github.com/llvm/llvm-project/pull/154994 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits