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

    <tr>
        <th>Summary</th>
        <td>
            Segfault when using type inference for op with attributes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    The problem arises precisely when all of the following are true:

1. The op has an attribute
2. The op has type inference
3. Type inference requires the attribute
4. The op does not explicitly require the type of output in its IR

```
def Foo_GetSliceOp : Foo_Op<"get_slice", [Pure, DeclareOpInterfaceMethods<InferTypeOpInterface, ["inferReturnTypes"]>]> {
  let arguments = (ins
      FooType:$input,
 IndexAttr:$start,
      IndexAttr:$size
  );
  let results = (outs
 FooType:$output
  );
  let assemblyFormat = "$input attr-dict `:` type($input) `->` type($output)";
}
```

Under these conditions, the generated parser runs type inference before it fully parses the attribute, so trying to write the following fails:
```
LogicalResult GetSliceOp::inferReturnTypes(
    MLIRContext* ctx, std::optional<Location>, ValueRange operands,
    DictionaryAttr attrs, mlir::PropertyRef properties,
    mlir::RegionRange regions, SmallVectorImpl<Type>& results) {
  GetSliceOpAdaptor op(operands, attrs, properties, regions);
  auto inputType = cast<lwe::FooType>(op.getInput().getType());
  int64_t start = op->getStart().getZExtValue(); // segfault here
  int64_t size = op->getSize().getZExtValue();
  ...
}
```

#88506 seems related, but this issue is still happening as of [this commit](https://github.com/llvm/llvm-project/commit/2cf353b5e8560723409f3f9164bddec76f499963).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVU2P2zgM_TXKhWjgSIkTH3zIZCaLAC1aZLo97KWQZdrWriJ5Jboz6a9fSE7Gk-wHsIExY5vi4yP5SMsQdGsRS7Z6YKvHmRyoc75U3qk_EOWscvW5_Noh9N5VBk8gvQ4YoPeodEBzhpcOLUhjw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