diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -1785,12 +1785,14 @@ auto module = allocOp.getParentOfType(); auto allocFunc = module.lookupSymbol(allocFuncName); if (!allocFunc) { - OpBuilder moduleBuilder(op->getParentOfType().getBodyRegion()); + OpBuilder::InsertionGuard guard(rewriter); + rewriter.setInsertionPointToStart( + op->getParentOfType().getBody()); SmallVector callArgTypes = {getIndexType()}; // aligned_alloc(size_t alignment, size_t size) if (useAlignedAlloc) callArgTypes.push_back(getIndexType()); - allocFunc = moduleBuilder.create( + allocFunc = rewriter.create( rewriter.getUnknownLoc(), allocFuncName, LLVM::LLVMType::getFunctionTy(getVoidPtrType(), callArgTypes, /*isVarArg=*/false)); @@ -2093,8 +2095,10 @@ auto freeFunc = op->getParentOfType().lookupSymbol("free"); if (!freeFunc) { - OpBuilder moduleBuilder(op->getParentOfType().getBodyRegion()); - freeFunc = moduleBuilder.create( + OpBuilder::InsertionGuard guard(rewriter); + rewriter.setInsertionPointToStart( + op->getParentOfType().getBody()); + freeFunc = rewriter.create( rewriter.getUnknownLoc(), "free", LLVM::LLVMType::getFunctionTy(getVoidType(), getVoidPtrType(), /*isVarArg=*/false));