Skip to content

Commit 614fe6d

Browse files
authored
[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
1 parent b32a2f4 commit 614fe6d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ struct OpenMPOpConversion : public ConvertOpToLLVMPattern<T> {
6666
for (NamedAttribute attr : op->getAttrs()) {
6767
if (auto typeAttr = dyn_cast<TypeAttr>(attr.getValue())) {
6868
Type convertedType = converter->convertType(typeAttr.getValue());
69+
if (!convertedType)
70+
return rewriter.notifyMatchFailure(
71+
op, "failed to convert type in attribute");
6972
convertedAttrs.emplace_back(attr.getName(),
7073
TypeAttr::get(convertedType));
7174
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: mlir-opt -convert-openmp-to-llvm -split-input-file -verify-diagnostics %s
2+
3+
// Indicates that the TypeConversion has failed for the MPMapInfoOp.
4+
// In this specific case, the `tensor` type (used in a TypeAttr) cannot be converted
5+
// to an LLVM type. This test ensures that the conversion fails gracefully with a
6+
// legalization error instead of crashing.
7+
func.func @fail_map_info_tensor_type(%arg0: memref<?xf32>) {
8+
// expected-error@+1 {{failed to legalize operation 'omp.map.info' that was explicitly marked illegal}}
9+
%map_info = omp.map.info var_ptr(%arg0: memref<?xf32>, tensor<?xf32>) map_clauses(to) capture(ByRef) -> memref<?xf32>
10+
omp.target_update map_entries(%map_info: memref<?xf32>) {
11+
omp.terminator
12+
}
13+
return
14+
}

0 commit comments

Comments
 (0)