[Mlir-commits] [mlir] 3a8db0f - [mlir] Reduce warnings for bad assertion in generated code
Valentin Clement
llvmlistbot at llvm.org
Tue Aug 1 14:57:37 PDT 2023
Author: Valentin Clement
Date: 2023-08-01T14:57:30-07:00
New Revision: 3a8db0f4bfb57348f49d9603119fa157114bbf8e
URL: https://github.com/llvm/llvm-project/commit/3a8db0f4bfb57348f49d9603119fa157114bbf8e
DIFF: https://github.com/llvm/llvm-project/commit/3a8db0f4bfb57348f49d9603119fa157114bbf8e.diff
LOG: [mlir] Reduce warnings for bad assertion in generated code
When the operation has no attributes, the generated assertion is
always false and triggers lots of warnings in the build.
```
warning: comparison of unsigned expression < 0 is always false
```
Just return a StringAttr when there is no attribute.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D156819
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 32c1a3b4d4186b..7da61ff991ec58 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -1095,12 +1095,16 @@ void OpEmitter::genAttrNameGetters() {
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 <attr>AttrName methods, that expose the attribute names to
More information about the Mlir-commits
mailing list