[Mlir-commits] [mlir] 7a9e3ef - [mlir] Fix crash in RewriterGen when a `TypeConstraint` is not given an argument
Markus Böck
llvmlistbot at llvm.org
Thu Feb 3 00:08:38 PST 2022
Author: Markus Böck
Date: 2022-02-03T09:08:27+01:00
New Revision: 7a9e3ef77a3c4dc1cffb8ae768db6207fdab1877
URL: https://github.com/llvm/llvm-project/commit/7a9e3ef77a3c4dc1cffb8ae768db6207fdab1877
DIFF: https://github.com/llvm/llvm-project/commit/7a9e3ef77a3c4dc1cffb8ae768db6207fdab1877.diff
LOG: [mlir] Fix crash in RewriterGen when a `TypeConstraint` is not given an argument
The code assumes that a TypeConstraint in the additional constraints list specifies precisely one argument.
If the user were to not specify any, it'd result in a crash. If given more than one, the additional ones were ignored.
This patch fixes the crash and disallows user errors by adding a check that a single argument is supplied to the TypeConstraint
Differential Revision: https://reviews.llvm.org/D118763
Added:
Modified:
mlir/test/mlir-tblgen/rewriter-errors.td
mlir/tools/mlir-tblgen/RewriterGen.cpp
Removed:
################################################################################
diff --git a/mlir/test/mlir-tblgen/rewriter-errors.td b/mlir/test/mlir-tblgen/rewriter-errors.td
index 597c6205b3d85..357a1cbe6945b 100644
--- a/mlir/test/mlir-tblgen/rewriter-errors.td
+++ b/mlir/test/mlir-tblgen/rewriter-errors.td
@@ -3,6 +3,8 @@
// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
+// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
+// RUN: not mlir-tblgen -gen-rewriters -I %S/../../include -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
include "mlir/IR/OpBase.td"
@@ -49,3 +51,15 @@ def : Pat<(OpB $val, AnyI32Attr:$attr), (OpA (OpA $val, $val, (returnType (OpA $
// ERROR5: [[@LINE+1]]:1: error: Cannot specify explicit return types in an op
def : Pat<(OpB $val, AnyI32Attr:$attr), (OpA $val, $val, (returnType "someType()"))>;
#endif
+
+#ifdef ERROR6
+// Check that type constraint has one argument
+// ERROR6: [[@LINE+1]]:1: error: type constraint requires exactly one argument
+def : Pat<(OpB:$result $val, $attr), (OpA $val, $val), [(AnyInteger:$result)]>;
+#endif
+
+#ifdef ERROR7
+// Check that type constraint has one argument
+// ERROR7: [[@LINE+1]]:1: error: type constraint requires exactly one argument
+def : Pat<(OpB:$opB $val, $attr), (OpA $val, $val), [(AnyInteger $opB, $val)]>;
+#endif
diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index 38f76c0cd6f54..e9ff5431a3ab0 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -853,6 +853,9 @@ void PatternEmitter::emitMatchLogic(DagNode tree, StringRef opName) {
auto condition = constraint.getConditionTemplate();
if (isa<TypeConstraint>(constraint)) {
+ if (entities.size() != 1)
+ PrintFatalError(loc, "type constraint requires exactly one argument");
+
auto self = formatv("({0}.getType())",
symbolInfoMap.getValueAndRangeUse(entities.front()));
emitMatchCheck(
More information about the Mlir-commits
mailing list