forked from OSchip/llvm-project
[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
This commit is contained in:
parent
67a9f82cc9
commit
7a9e3ef77a
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue