diff --git a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp index 021e31a8ecd97..7fdc23adc8573 100644 --- a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp +++ b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp @@ -66,6 +66,9 @@ struct OpenMPOpConversion : public ConvertOpToLLVMPattern { for (NamedAttribute attr : op->getAttrs()) { if (auto typeAttr = dyn_cast(attr.getValue())) { Type convertedType = converter->convertType(typeAttr.getValue()); + if (!convertedType) + return rewriter.notifyMatchFailure( + op, "failed to convert type in attribute"); convertedAttrs.emplace_back(attr.getName(), TypeAttr::get(convertedType)); } else { diff --git a/mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir b/mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir new file mode 100644 index 0000000000000..3bd9bb4aee791 --- /dev/null +++ b/mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir @@ -0,0 +1,14 @@ +// RUN: mlir-opt -convert-openmp-to-llvm -split-input-file -verify-diagnostics %s + +// Indicates that the TypeConversion has failed for the MPMapInfoOp. +// In this specific case, the `tensor` type (used in a TypeAttr) cannot be converted +// to an LLVM type. This test ensures that the conversion fails gracefully with a +// legalization error instead of crashing. +func.func @fail_map_info_tensor_type(%arg0: memref) { + // expected-error@+1 {{failed to legalize operation 'omp.map.info' that was explicitly marked illegal}} + %map_info = omp.map.info var_ptr(%arg0: memref, tensor) map_clauses(to) capture(ByRef) -> memref + omp.target_update map_entries(%map_info: memref) { + omp.terminator + } + return +}