[Mlir-commits] [mlir] bea0b1a - [mlir][ods] Assert on static getAttrName methods
Jeff Niu
llvmlistbot at llvm.org
Wed Oct 12 17:56:22 PDT 2022
Author: Jeff Niu
Date: 2022-10-12T17:56:14-07:00
New Revision: bea0b1a896f55684eff0d5dbbbb73327448f698a
URL: https://github.com/llvm/llvm-project/commit/bea0b1a896f55684eff0d5dbbbb73327448f698a
DIFF: https://github.com/llvm/llvm-project/commit/bea0b1a896f55684eff0d5dbbbb73327448f698a.diff
LOG: [mlir][ods] Assert on static getAttrName methods
This patch makes ODS insert an assert when calling static `get*AttrName`
methods with a `OperationName` that the name is the same as the op's.
This prevents accidentally passing the wrong kind of name and getting an
erroneous attribute name.
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D135698
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 546c71e99052..6304f74ea8e9 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -907,6 +907,7 @@ void OpEmitter::genAttrNameGetters() {
const char *const getAttrName = R"(
assert(index < {0} && "invalid attribute index");
+ assert(name.getStringRef() == getOperationName() && "invalid operation name");
return name.getRegisteredInfo()->getAttributeNames()[index];
)";
method->body() << formatv(getAttrName, attributes.size());
More information about the Mlir-commits
mailing list