@@ -5953,6 +5953,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
59535953
59545954static LogicalResult
59555955convertDeclareTargetAttr (Operation *op, mlir::omp::DeclareTargetAttr attribute,
5956+ llvm::OpenMPIRBuilder *ompBuilder,
59565957 LLVM::ModuleTranslation &moduleTranslation) {
59575958 // Amend omp.declare_target by deleting the IR of the outlined functions
59585959 // created for target regions. They cannot be filtered out from MLIR earlier
@@ -5975,6 +5976,11 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
59755976 moduleTranslation.lookupFunction (funcOp.getName ());
59765977 llvmFunc->dropAllReferences ();
59775978 llvmFunc->eraseFromParent ();
5979+
5980+ // Invalidate the builder's current insertion point, as it now points to
5981+ // a deleted block.
5982+ ompBuilder->Builder .ClearInsertionPoint ();
5983+ ompBuilder->Builder .SetCurrentDebugLocation (llvm::DebugLoc ());
59785984 }
59795985 }
59805986 return success ();
@@ -6512,9 +6518,12 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
65126518 .Case (" omp.declare_target" ,
65136519 [&](Attribute attr) {
65146520 if (auto declareTargetAttr =
6515- dyn_cast<omp::DeclareTargetAttr>(attr))
6521+ dyn_cast<omp::DeclareTargetAttr>(attr)) {
6522+ llvm::OpenMPIRBuilder *ompBuilder =
6523+ moduleTranslation.getOpenMPBuilder ();
65166524 return convertDeclareTargetAttr (op, declareTargetAttr,
6517- moduleTranslation);
6525+ ompBuilder, moduleTranslation);
6526+ }
65186527 return failure ();
65196528 })
65206529 .Case (" omp.requires" ,
0 commit comments