From bea0b1a896f55684eff0d5dbbbb73327448f698a Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Tue, 11 Oct 2022 10:40:23 -0700 Subject: [PATCH] [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 --- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 546c71e..6304f74 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()); -- 2.7.4