forked from OSchip/llvm-project
Add sanity check in MLIR ODS to catch case where two results have the same name
This is making a tablegen crash with a more friendly error. Differential Revision: https://reviews.llvm.org/D109456
This commit is contained in:
parent
717ed1c310
commit
4eaaf05394
|
@ -1,6 +1,8 @@
|
|||
// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
|
||||
// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
|
||||
// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
|
||||
// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
|
||||
// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
|
||||
|
||||
include "mlir/IR/OpBase.td"
|
||||
|
||||
|
@ -34,3 +36,17 @@ def OpDefaultValueNotTrailing : Op<Test_Dialect, "default_value"> {
|
|||
];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ERROR4
|
||||
// ERROR4: error: op has two operands with the same name: 'tensor'
|
||||
def OpWithDuplicatedArgNames : Op<Test_Dialect, "default_value"> {
|
||||
let arguments = (ins AnyTensor:$tensor, AnyTensor:$tensor);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ERROR5
|
||||
// ERROR5: error: op has two results with the same name: 'tensor'
|
||||
def OpWithDuplicatedResultNames : Op<Test_Dialect, "default_value"> {
|
||||
let results = (outs AnyTensor:$tensor, AnyTensor:$tensor);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -857,7 +857,8 @@ static void generateNamedOperandGetters(const Operator &op, Class &opClass,
|
|||
if (operand.name.empty())
|
||||
continue;
|
||||
if (!operandNames.insert(operand.name).second)
|
||||
PrintFatalError(op.getLoc(), "op has two operands with the same name");
|
||||
PrintFatalError(op.getLoc(), "op has two operands with the same name: '" +
|
||||
operand.name + "'");
|
||||
|
||||
if (operand.isOptional()) {
|
||||
m = opClass.addMethodAndPrune("::mlir::Value", operand.name);
|
||||
|
@ -991,10 +992,14 @@ void OpEmitter::genNamedResultGetters() {
|
|||
m->body() << formatv(valueRangeReturnCode, "getOperation()->result_begin()",
|
||||
"getODSResultIndexAndLength(index)");
|
||||
|
||||
SmallDenseSet<StringRef> resultNames;
|
||||
for (int i = 0; i != numResults; ++i) {
|
||||
const auto &result = op.getResult(i);
|
||||
if (result.name.empty())
|
||||
continue;
|
||||
if (!resultNames.insert(result.name).second)
|
||||
PrintFatalError(op.getLoc(), "op has two results with the same name: '" +
|
||||
result.name + "'");
|
||||
|
||||
if (result.isOptional()) {
|
||||
m = opClass.addMethodAndPrune("::mlir::Value", result.name);
|
||||
|
|
Loading…
Reference in New Issue