[Mlir-commits] [mlir] [mlir][openmp] Fix crash in MapInfoOp conversion when type conversion fails (PR #171045)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Dec 7 08:27:12 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Men-cotton (Men-cotton)

<details>
<summary>Changes</summary>

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 

---
Full diff: https://github.com/llvm/llvm-project/pull/171045.diff


2 Files Affected:

- (modified) mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp (+3) 
- (added) mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir (+14) 


``````````diff
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
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/171045


More information about the Mlir-commits mailing list