@@ -5872,6 +5872,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
58725872
58735873static LogicalResult
58745874convertDeclareTargetAttr (Operation *op, mlir::omp::DeclareTargetAttr attribute,
5875+ llvm::OpenMPIRBuilder *ompBuilder,
58755876 LLVM::ModuleTranslation &moduleTranslation) {
58765877 // Amend omp.declare_target by deleting the IR of the outlined functions
58775878 // created for target regions. They cannot be filtered out from MLIR earlier
@@ -5894,6 +5895,11 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
58945895 moduleTranslation.lookupFunction (funcOp.getName ());
58955896 llvmFunc->dropAllReferences ();
58965897 llvmFunc->eraseFromParent ();
5898+
5899+ // Invalidate the builder's current insertion point, as it now points to
5900+ // a deleted block.
5901+ ompBuilder->Builder .ClearInsertionPoint ();
5902+ ompBuilder->Builder .SetCurrentDebugLocation (llvm::DebugLoc ());
58975903 }
58985904 }
58995905 return success ();
@@ -6338,9 +6344,12 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
63386344 .Case (" omp.declare_target" ,
63396345 [&](Attribute attr) {
63406346 if (auto declareTargetAttr =
6341- dyn_cast<omp::DeclareTargetAttr>(attr))
6347+ dyn_cast<omp::DeclareTargetAttr>(attr)) {
6348+ llvm::OpenMPIRBuilder *ompBuilder =
6349+ moduleTranslation.getOpenMPBuilder ();
63426350 return convertDeclareTargetAttr (op, declareTargetAttr,
6343- moduleTranslation);
6351+ ompBuilder, moduleTranslation);
6352+ }
63446353 return failure ();
63456354 })
63466355 .Case (" omp.requires" ,
0 commit comments