[Mlir-commits] [mlir] 780a209 - [PDLL]: Fix crash when negation doesn't apply to native constraint (#84331)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Mar 7 23:27:49 PST 2024


Author: Matthias Gehre
Date: 2024-03-08T08:27:46+01:00
New Revision: 780a20984b6af067eed5870eb7c00ea076b6072a

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

LOG: [PDLL]: Fix crash when negation doesn't apply to native constraint (#84331)

Fixes that
```
Pattern {
  let tuple = (attr<"3 : i34">);
  not tuple.0;
  erase _;
}
```
would crash the PDLL parser because it expected a native constraint
after `not`.

Added: 
    

Modified: 
    mlir/lib/Tools/PDLL/Parser/Parser.cpp
    mlir/test/mlir-pdll/Parser/expr-failure.pdll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
index 206781ed146692..9f931f4fce001c 100644
--- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp
+++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
@@ -1968,6 +1968,8 @@ FailureOr<ast::Expr *> Parser::parseNegatedExpr() {
   FailureOr<ast::Expr *> identifierExpr = parseIdentifierExpr();
   if (failed(identifierExpr))
     return failure();
+  if (!curToken.is(Token::l_paren))
+    return emitError("expected `(` after function name");
   return parseCallExpr(*identifierExpr, /*isNegated = */ true);
 }
 

diff  --git a/mlir/test/mlir-pdll/Parser/expr-failure.pdll b/mlir/test/mlir-pdll/Parser/expr-failure.pdll
index 253d770c83e58a..898fe8680a763f 100644
--- a/mlir/test/mlir-pdll/Parser/expr-failure.pdll
+++ b/mlir/test/mlir-pdll/Parser/expr-failure.pdll
@@ -205,6 +205,23 @@ Pattern {
 
 // -----
 
+Pattern {
+  // CHECK: expected native constraint
+  not attr<"0 : i1">
+  erase _;
+}
+
+// -----
+
+Pattern {
+  let tuple = (attr<"3 : i34">);
+  // CHECK: expected `(` after function name
+  not tuple.0;
+  erase _;
+}
+
+// -----
+
 Pattern {
   // CHECK: expected expression
   let tuple = (10 = _: Value);


        


More information about the Mlir-commits mailing list