[Mlir-commits] [mlir] 39dd297 - [mlir][emitc] Disallow !emitc.opaque pointers
Marius Brehler
llvmlistbot at llvm.org
Thu Apr 28 08:09:43 PDT 2022
Author: Marius Brehler
Date: 2022-04-28T15:08:21Z
New Revision: 39dd29736ffa8e027400a2655861ca36929004a6
URL: https://github.com/llvm/llvm-project/commit/39dd29736ffa8e027400a2655861ca36929004a6
DIFF: https://github.com/llvm/llvm-project/commit/39dd29736ffa8e027400a2655861ca36929004a6.diff
LOG: [mlir][emitc] Disallow !emitc.opaque pointers
Fordbids to express pointer via the `!emitc.opaque` type. Point the user
to use the `!emitc.ptr` type instead.
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D124002
Added:
Modified:
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/test/Dialect/EmitC/invalid_types.mlir
mlir/test/Dialect/EmitC/types.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index e89b68116dc76..a1e6db238f607 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -220,6 +220,11 @@ Type emitc::OpaqueType::parse(AsmParser &parser) {
parser.emitError(loc) << "expected non empty string in !emitc.opaque type";
return Type();
}
+ if (value.back() == '*') {
+ parser.emitError(loc) << "pointer not allowed as outer type with "
+ "!emitc.opaque, use !emitc.ptr instead";
+ return Type();
+ }
if (parser.parseGreater())
return Type();
return get(parser.getContext(), value);
diff --git a/mlir/test/Dialect/EmitC/invalid_types.mlir b/mlir/test/Dialect/EmitC/invalid_types.mlir
index f47361378a79e..54e3775ddb8ed 100644
--- a/mlir/test/Dialect/EmitC/invalid_types.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_types.mlir
@@ -4,3 +4,10 @@ func.func @illegal_opaque_type_1() {
// expected-error @+1 {{expected non empty string in !emitc.opaque type}}
%1 = "emitc.variable"(){value = "42" : !emitc.opaque<"">} : () -> !emitc.opaque<"mytype">
}
+
+// -----
+
+func.func @illegal_opaque_type_2() {
+ // expected-error @+1 {{pointer not allowed as outer type with !emitc.opaque, use !emitc.ptr instead}}
+ %1 = "emitc.variable"(){value = "nullptr" : !emitc.opaque<"int32_t*">} : () -> !emitc.opaque<"int32_t*">
+}
diff --git a/mlir/test/Dialect/EmitC/types.mlir b/mlir/test/Dialect/EmitC/types.mlir
index 480bf1dd444ed..76f315b1bf296 100644
--- a/mlir/test/Dialect/EmitC/types.mlir
+++ b/mlir/test/Dialect/EmitC/types.mlir
@@ -14,6 +14,8 @@ func.func @opaque_types() {
emitc.call "f"() {template_args = [!emitc<"opaque<\"status_t\">">]} : () -> ()
// CHECK-NEXT: !emitc.opaque<"std::vector<std::string>">
emitc.call "f"() {template_args = [!emitc.opaque<"std::vector<std::string>">]} : () -> ()
+ // CHECK-NEXT: !emitc.opaque<"SmallVector<int*, 4>">
+ emitc.call "f"() {template_args = [!emitc.opaque<"SmallVector<int*, 4>">]} : () -> ()
return
}
More information about the Mlir-commits
mailing list