Skip to content

Commit fce7219

Browse files
committed
Make trailing '{' illegal
1 parent 7c563b1 commit fce7219

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ parseFormatString(StringRef toParse, ArgType fmtArgs,
200200
continue;
201201
}
202202
if (toParse.size() < 2) {
203-
// '{' is last character
204-
items.push_back(toParse);
205-
break;
203+
return (*emitError)()
204+
<< "expected '}' after unescaped '{' at end of string";
206205
}
207206
// toParse contains at least two characters and starts with `{`.
208207
char nextChar = toParse[1];

mlir/test/Dialect/EmitC/invalid_ops.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,14 @@ func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
577577

578578
// -----
579579

580+
func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
581+
// expected-error @+1 {{'emitc.verbatim' op expected '}' after unescaped '{' at end of string}}
582+
emitc.verbatim "{} + {} {" args %arg0, %arg1 : !emitc.ptr<i32>, i32
583+
return
584+
}
585+
586+
// -----
587+
580588
func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
581589
// expected-error @+1 {{'emitc.verbatim' op requires operands for each placeholder in the format string}}
582590
emitc.verbatim "abc" args %arg0, %arg1 : !emitc.ptr<i32>, i32

mlir/test/Dialect/EmitC/ops.mlir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ emitc.verbatim "{} { }"
244244
func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
245245
emitc.verbatim "{} + {};" args %arg0, %arg1 : !emitc.ptr<i32>, i32
246246

247-
// Trailing '{' are ok and don't start a placeholder.
248-
emitc.verbatim "{} + {} {" args %arg0, %arg1 : !emitc.ptr<i32>, i32
249-
250247
// Check there is no ambiguity whether %a is the argument to the emitc.verbatim op.
251248
emitc.verbatim "a"
252249
%a = "emitc.constant"(){value = 42 : i32} : () -> i32

mlir/test/Target/Cpp/verbatim.mlir

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ emitc.func @func(%arg: f32) {
3434
emitc.verbatim "#pragma my var={} property" args %arg : f32
3535
// CHECK-NEXT: #pragma my var=[[V0]] property
3636

37-
// Trailing '{' are printed as-is.
38-
emitc.verbatim "#pragma my var={} {" args %arg : f32
39-
// CHECK-NEXT: #pragma my var=[[V0]] {
40-
4137
emitc.verbatim "#pragma my2 var={} property" args %a : !emitc.array<3x7xi32>
4238
// CHECK-NEXT: #pragma my2 var=[[A]] property
4339

0 commit comments

Comments
 (0)