[Mlir-commits] [mlir] bab3d37 - [mlir][LLVM] Fix crash when using opaque pointers in function signatures
Markus Böck
llvmlistbot at llvm.org
Fri Apr 22 15:12:35 PDT 2022
Author: Markus Böck
Date: 2022-04-23T00:10:31+02:00
New Revision: bab3d3778de17c0a62cc7fb8757ce942ce332fc2
URL: https://github.com/llvm/llvm-project/commit/bab3d3778de17c0a62cc7fb8757ce942ce332fc2
DIFF: https://github.com/llvm/llvm-project/commit/bab3d3778de17c0a62cc7fb8757ce942ce332fc2.diff
LOG: [mlir][LLVM] Fix crash when using opaque pointers in function signatures
Using opaque pointers in function signatures leads to an attempt to recursively convert all types, including sub types in LLVM types. In the case of LLVM pointers, it may not have a subtype aka element type if it is opaque which would then lead to a null pointer dereference.
Differential Revision: https://reviews.llvm.org/D124291
Added:
Modified:
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
mlir/test/Conversion/FuncToLLVM/convert-types.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index e64487edd268c..2c0631b9154f2 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -49,6 +49,8 @@ LLVMTypeConverter::LLVMTypeConverter(MLIRContext *ctx,
// LLVM container types may (recursively) contain other types that must be
// converted even when the outer type is compatible.
addConversion([&](LLVM::LLVMPointerType type) -> llvm::Optional<Type> {
+ if (type.isOpaque())
+ return type;
if (auto pointee = convertType(type.getElementType()))
return LLVM::LLVMPointerType::get(pointee, type.getAddressSpace());
return llvm::None;
diff --git a/mlir/test/Conversion/FuncToLLVM/convert-types.mlir b/mlir/test/Conversion/FuncToLLVM/convert-types.mlir
index 9cdc38730f357..fd618b7bc4ffa 100644
--- a/mlir/test/Conversion/FuncToLLVM/convert-types.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/convert-types.mlir
@@ -4,6 +4,11 @@
// CHECK: !llvm.ptr<i42>
func.func private @ptr() -> !llvm.ptr<!test.smpla>
+// CHECK-LABEL: @opaque_ptr
+// CHECK: !llvm.ptr
+// CHECK-NOT: <
+func.func private @opaque_ptr() -> !llvm.ptr
+
// CHECK-LABEL: @ptr_ptr()
// CHECK: !llvm.ptr<ptr<i42>>
func.func private @ptr_ptr() -> !llvm.ptr<!llvm.ptr<!test.smpla>>
More information about the Mlir-commits
mailing list