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

Matthias Gehre llvmlistbot at llvm.org
Thu Mar 7 07:16:35 PST 2024


https://github.com/mgehre-amd created https://github.com/llvm/llvm-project/pull/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`.

>From 072ba5ced91530ec2682100d4a7e7fabb9970497 Mon Sep 17 00:00:00 2001
From: Matthias Gehre <matthias.gehre at amd.com>
Date: Fri, 26 Jan 2024 23:04:56 +0100
Subject: [PATCH] [PDLL]: Fix crash when negation doesn't apply to native
 constraint

The new test cases used to crash the PDLL parser.
---
 mlir/lib/Tools/PDLL/Parser/Parser.cpp        |  2 ++
 mlir/test/mlir-pdll/Parser/expr-failure.pdll | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

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