Skip to content

Commit

Permalink
[mlir][ods] Assert on static getAttrName methods
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mogball committed Oct 13, 2022
1 parent e936c3b commit bea0b1a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit bea0b1a

Please sign in to comment.