Unverified Commit 3a8db0f4 authored by Valentin Clement's avatar Valentin Clement
Browse files

[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
parent a82b154e
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1095,6 +1095,9 @@ void OpEmitter::genAttrNameGetters() {
        MethodParameter("unsigned", "index"));
    ERROR_IF_PRUNED(method, "getAttributeNameForIndex", op);

    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");
@@ -1102,6 +1105,7 @@ void OpEmitter::genAttrNameGetters() {
)";
      method->body() << formatv(getAttrName, attributes.size());
    }
  }

  // Generate the <attr>AttrName methods, that expose the attribute names to
  // users.