diff --git a/mlir/test/mlir-tblgen/op-error.td b/mlir/test/mlir-tblgen/op-error.td --- a/mlir/test/mlir-tblgen/op-error.td +++ b/mlir/test/mlir-tblgen/op-error.td @@ -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 @@ ]; } #endif + +#ifdef ERROR4 +// ERROR4: error: op has two operands with the same name: 'tensor' +def OpWithDuplicatedArgNames : Op { + let arguments = (ins AnyTensor:$tensor, AnyTensor:$tensor); +} +#endif + +#ifdef ERROR5 +// ERROR5: error: op has two results with the same name: 'tensor' +def OpWithDuplicatedResultNames : Op { + let results = (outs AnyTensor:$tensor, AnyTensor:$tensor); +} +#endif diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -857,7 +857,8 @@ 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 @@ m->body() << formatv(valueRangeReturnCode, "getOperation()->result_begin()", "getODSResultIndexAndLength(index)"); + SmallDenseSet 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);