[Mlir-commits] [mlir] b743ff1 - [mlir] Relax restriction on name location parsing

Jacques Pienaar llvmlistbot at llvm.org
Sun Dec 12 08:07:47 PST 2021


Author: Jacques Pienaar
Date: 2021-12-12T08:06:59-08:00
New Revision: b743ff161b8296f4f85d095582579e290117d823

URL: https://github.com/llvm/llvm-project/commit/b743ff161b8296f4f85d095582579e290117d823
DIFF: https://github.com/llvm/llvm-project/commit/b743ff161b8296f4f85d095582579e290117d823.diff

LOG: [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

Added: 
    

Modified: 
    mlir/lib/Parser/LocationParser.cpp
    mlir/test/IR/invalid-locations.mlir
    mlir/test/IR/locations.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Parser/LocationParser.cpp b/mlir/lib/Parser/LocationParser.cpp
index 469fa9f6a9bf1..c81d0d673951d 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<NameLoc>())
-      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 175ab34706c53..131b33426fe4c 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 70d51226b3a43..0016c3ec6611b 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")


        


More information about the Mlir-commits mailing list