From b743ff161b8296f4f85d095582579e290117d823 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Sun, 12 Dec 2021 08:06:59 -0800 Subject: [PATCH] [mlir] Relax restriction on name location parsing We currently restrict parsing of location to not allow nameloc being nested inside nameloc. This restriction may be historical as there doesn't seem to be a reason for it anymore (locations like this can be constructed in C++ and they print fine). Relax this restriction in the parser to allow this nesting. Differential Revision: https://reviews.llvm.org/D115581 --- mlir/lib/Parser/LocationParser.cpp | 6 ------ mlir/test/IR/invalid-locations.mlir | 7 ------- mlir/test/IR/locations.mlir | 6 ++++++ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/mlir/lib/Parser/LocationParser.cpp b/mlir/lib/Parser/LocationParser.cpp index 469fa9f..c81d0d6 100644 --- a/mlir/lib/Parser/LocationParser.cpp +++ b/mlir/lib/Parser/LocationParser.cpp @@ -126,17 +126,11 @@ ParseResult Parser::parseNameOrFileLineColLocation(LocationAttr &loc) { // Check for a child location. if (consumeIf(Token::l_paren)) { - auto childSourceLoc = getToken().getLoc(); - // Parse the child location. LocationAttr childLoc; if (parseLocationInstance(childLoc)) return failure(); - // The child must not be another NameLoc. - if (childLoc.isa()) - return emitError(childSourceLoc, - "child of NameLoc cannot be another NameLoc"); loc = NameLoc::get(StringAttr::get(ctx, str), childLoc); // Parse the closing ')'. diff --git a/mlir/test/IR/invalid-locations.mlir b/mlir/test/IR/invalid-locations.mlir index 175ab34..131b334 100644 --- a/mlir/test/IR/invalid-locations.mlir +++ b/mlir/test/IR/invalid-locations.mlir @@ -30,13 +30,6 @@ func @location_name_missing_r_paren() { // ----- -func @location_name_child_is_name() { -^bb: - return loc("foo"("foo")) // expected-error {{child of NameLoc cannot be another NameLoc}} -} - -// ----- - func @location_callsite_missing_l_paren() { ^bb: return loc(callsite unknown // expected-error {{expected '(' in callsite location}} diff --git a/mlir/test/IR/locations.mlir b/mlir/test/IR/locations.mlir index 70d5122..0016c3e 100644 --- a/mlir/test/IR/locations.mlir +++ b/mlir/test/IR/locations.mlir @@ -69,5 +69,11 @@ func @argLocs(%x: i32, "foo.yield"(%1) : (i32) -> () }) : () -> () +// CHECK-LABEL: func @location_name_child_is_name +func @location_name_child_is_name() { + // CHECK: "foo"("foo") + return loc("foo"("foo")) +} + // CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location") #loc = loc("out_of_line_location") -- 2.7.4