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 @@ -1095,12 +1095,16 @@ MethodParameter("unsigned", "index")); ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op); - const char *const getAttrName = R"( + if (attributes.empty()) { + method->body() << " return {};"; + } else { + const char *const getAttrName = R"( assert(index < {0} && "invalid attribute index"); assert(name.getStringRef() == getOperationName() && "invalid operation name"); return name.getAttributeNames()[index]; )"; - method->body() << formatv(getAttrName, attributes.size()); + method->body() << formatv(getAttrName, attributes.size()); + } } // Generate the AttrName methods, that expose the attribute names to