[Mlir-commits] [mlir] 6f1f30a - Add sanity check in MLIR ODS to catch case where two operands have the same name
Mehdi Amini
llvmlistbot at llvm.org
Wed Sep 8 09:59:07 PDT 2021
Author: Mehdi Amini
Date: 2021-09-08T16:58:57Z
New Revision: 6f1f30a95708e847745cbe6b3703be67c16f9847
URL: https://github.com/llvm/llvm-project/commit/6f1f30a95708e847745cbe6b3703be67c16f9847
DIFF: https://github.com/llvm/llvm-project/commit/6f1f30a95708e847745cbe6b3703be67c16f9847.diff
LOG: Add sanity check in MLIR ODS to catch case where two operands have the same name
This is making a tablegen crash into a more friendly error.
Differential Revision: https://reviews.llvm.org/D109449
Added:
Modified:
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 220f8438aebe3..a182e268be3c1 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -850,10 +850,14 @@ static void generateNamedOperandGetters(const Operator &op, Class &opClass,
// Then we emit nicer named getter methods by redirecting to the "sink" getter
// method.
+ // Keep track of the operand names to find duplicates.
+ SmallDenseSet<StringRef> operandNames;
for (int i = 0; i != numOperands; ++i) {
const auto &operand = op.getOperand(i);
if (operand.name.empty())
continue;
+ if (!operandNames.insert(operand.name).second)
+ PrintFatalError(op.getLoc(), "op has two operands with the same name");
if (operand.isOptional()) {
m = opClass.addMethodAndPrune("::mlir::Value", operand.name);
More information about the Mlir-commits
mailing list