<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61193>61193</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir asmprinter] OpAsmDialectInterface doesn't handle UnitAttr correctly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:core
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lattner
      </td>
    </tr>
</table>

<pre>
    I recently tried to introduce a UnitAttr attribute to an op, and got a crash in OpAsmDialectInterface.  UnitAttrs are weird in that they can (validly) be null.  The ODS generated print method looks like this:

```
FooOp::print(...) {
  5496    _odsPrinter << ' ';
 5497     _odsPrinter.printAttributeWithoutType(getNameAttr());
   5498  _odsPrinter << ' ';
-> 5499       _odsPrinter.printAttributeWithoutType(getIsUnitPropertyAttr());
   5500  _odsPrinter << ' ' << ":";
   5501   _odsPrinter << ' ';
```

which is unconditionally printing the unit attr even though it may be null.  The asmprinter then goes on to call `AliasInitializer::visit` to see if there is an alias for the attribute, which then crashes in `BuiltinOpAsmDialectInterface::getAlias` which assumes the attribute is non-null:

```
LogicalResult AliasState::getAlias(Attribute attr, raw_ostream &os) const {
  auto it = attrTypeToAlias.find(attr.getAsOpaquePointer());
  if (it == attrTypeToAlias.end())
    return failure();
 it->second.print(os);
  return success();
}
```

I'm not really sure what level is supposed to handle the null, but something should.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVcFu4zYQ_Rr6MohAU5YsHXzwxjUQoGgW3S16XNDSWGKXIlVymMD9-mJoO8kaabqATEP243sznDdDHaMZHOJGVJ9EtVvoRKMPG6uJHIbFwfenzQME7NCRPQEFgz2QB-Mo-D51CBr-cIa2RAE0UTCHRMgI7cDPQt2Ddj0MnkBDF3QcwTh4nLdx2hltsaMHRxiOusMCXpgi6IDwjCb0DKdRE9CIJ-i0A6GaJ21Nb09C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