diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -220,6 +220,11 @@ 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 --- a/mlir/test/Dialect/EmitC/invalid_types.mlir +++ b/mlir/test/Dialect/EmitC/invalid_types.mlir @@ -4,3 +4,10 @@ // expected-error @+1 {{expected non empty string in !emitc.opaque type}} %1 = "emitc.variable"(){value = "42" : !emitc.opaque<"">} : () -> !emitc.opaque<"mytype"> } + +// ----- + +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 --- a/mlir/test/Dialect/EmitC/types.mlir +++ b/mlir/test/Dialect/EmitC/types.mlir @@ -14,6 +14,8 @@ emitc.call "f"() {template_args = [!emitc<"opaque<\"status_t\">">]} : () -> () // CHECK-NEXT: !emitc.opaque<"std::vector"> emitc.call "f"() {template_args = [!emitc.opaque<"std::vector">]} : () -> () + // CHECK-NEXT: !emitc.opaque<"SmallVector"> + emitc.call "f"() {template_args = [!emitc.opaque<"SmallVector">]} : () -> () return }