[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:26:42 PST 2025
https://github.com/Men-cotton created https://github.com/llvm/llvm-project/pull/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
>From 0817ff5213a5c7c7c65a75a3dcb73858895747ff Mon Sep 17 00:00:00 2001
From: mencotton <mencotton0410 at gmail.com>
Date: Mon, 8 Dec 2025 01:07:09 +0900
Subject: [PATCH] [mlir][openmp] Fix crash in MapInfoOp conversion when type
conversion fails
---
mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp | 3 +++
.../map-info-type-conversion-fail.mlir | 14 ++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 mlir/test/Conversion/OpenMPToLLVM/map-info-type-conversion-fail.mlir
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