Skip to content

Commit 39dd297

Browse files
committed
[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
1 parent 501cc4a commit 39dd297

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ Type emitc::OpaqueType::parse(AsmParser &parser) {
220220
parser.emitError(loc) << "expected non empty string in !emitc.opaque type";
221221
return Type();
222222
}
223+
if (value.back() == '*') {
224+
parser.emitError(loc) << "pointer not allowed as outer type with "
225+
"!emitc.opaque, use !emitc.ptr instead";
226+
return Type();
227+
}
223228
if (parser.parseGreater())
224229
return Type();
225230
return get(parser.getContext(), value);

mlir/test/Dialect/EmitC/invalid_types.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ func.func @illegal_opaque_type_1() {
44
// expected-error @+1 {{expected non empty string in !emitc.opaque type}}
55
%1 = "emitc.variable"(){value = "42" : !emitc.opaque<"">} : () -> !emitc.opaque<"mytype">
66
}
7+
8+
// -----
9+
10+
func.func @illegal_opaque_type_2() {
11+
// expected-error @+1 {{pointer not allowed as outer type with !emitc.opaque, use !emitc.ptr instead}}
12+
%1 = "emitc.variable"(){value = "nullptr" : !emitc.opaque<"int32_t*">} : () -> !emitc.opaque<"int32_t*">
13+
}

mlir/test/Dialect/EmitC/types.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func.func @opaque_types() {
1414
emitc.call "f"() {template_args = [!emitc<"opaque<\"status_t\">">]} : () -> ()
1515
// CHECK-NEXT: !emitc.opaque<"std::vector<std::string>">
1616
emitc.call "f"() {template_args = [!emitc.opaque<"std::vector<std::string>">]} : () -> ()
17+
// CHECK-NEXT: !emitc.opaque<"SmallVector<int*, 4>">
18+
emitc.call "f"() {template_args = [!emitc.opaque<"SmallVector<int*, 4>">]} : () -> ()
1719

1820
return
1921
}

0 commit comments

Comments
 (0)