[Mlir-commits] [mlir] 614fe6d - [mlir][OpenMP] Fix crash in MapInfoOp conversion when type conversion fails (#171045)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 8 08:30:26 PST 2025
Author: Men-cotton
Date: 2025-12-08T17:30:22+01:00
New Revision: 614fe6da145e883cb0aa1b1406bbd5e5d103747b
URL: https://github.com/llvm/llvm-project/commit/614fe6da145e883cb0aa1b1406bbd5e5d103747b
DIFF: https://github.com/llvm/llvm-project/commit/614fe6da145e883cb0aa1b1406bbd5e5d103747b.diff
LOG: [mlir][OpenMP] Fix crash in MapInfoOp conversion when type conversion fails (#171045)
Check the result of `convertType` before calling `TypeAttr::get`. This
prevents a crash on unsupported types (e.g. `tensor`) by ensuring the
pattern fails gracefully.
Added regression test: map-info-type-conversion-fail.mlir
Fixes: #108159
Added:
mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir
Modified:
mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
Removed:
################################################################################
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<T> {
for (NamedAttribute attr : op->getAttrs()) {
if (auto typeAttr = dyn_cast<TypeAttr>(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<?xf32>) {
+ // expected-error at +1 {{failed to legalize operation 'omp.map.info' that was explicitly marked illegal}}
+ %map_info = omp.map.info var_ptr(%arg0: memref<?xf32>, tensor<?xf32>) map_clauses(to) capture(ByRef) -> memref<?xf32>
+ omp.target_update map_entries(%map_info: memref<?xf32>) {
+ omp.terminator
+ }
+ return
+}
More information about the Mlir-commits
mailing list