Issue 64724
Summary [mlir] Invalid parser generated for optional parameter in attribute
Labels mlir
Assignees
Reporter mortbopet
    git version: [5bf8de8](https://github.com/llvm/llvm-project/tree/5bf8de882ae96a53fdd15eef1682b9168d3d16a2)

In the following, `PathStepAttr` describes an attribute with an optional field `child` - this compiles successfully.

```tablegen
def PathDirection : I32EnumAttr<"PathDirection", "path direction", [
 I32EnumAttrCase<"Parent", 0, "parent">,
  I32EnumAttrCase<"Child", 1, "child">
]>;

def PathStepAttr : AttrDef<IbisDialect, "PathStep", [TypedAttrInterface]> {
  let description = "Used to describe a single step in a path";
  let parameters = (ins
 "PathDirection":$direction,
 AttributeSelfTypeParameter<"">:$type,
 OptionalParameter<"mlir::FlatSymbolRefAttr">:$child
  );
  let mnemonic = "step";
  let assemblyFormat = "`<` $direction ($child^)? `:` $type  `>`";
}
```

However, trying to pass what to my eyes is valid IR, fails:
```mlir
  %some_parent = ibis.path [#ibis.step<parent : !ibis.scoperef>]
  %some_child = ibis.path [#ibis.step<child @a : !ibis.scoperef>]

// fails with

round-trip.mlir:48:45: error: expected attribute value
 %some_child = ibis.path [#ibis.step<parent  : !ibis.scoperef>]
 ^
round-trip.mlir:48:47: error: failed to parse PathStepAttr parameter 'child' which is to be a `mlir::FlatSymbolRefAttr`
  %some_child = ibis.path [#ibis.step<parent  : !ibis.scoperef>]
```

If we instead insert some keyword before `$child`, e.g. `,`:
```td
  let assemblyFormat = "`<` $direction (`,` $child^)? `:` $type  `>`";
```

things parse successfully:
```mlir
  %some_parent = ibis.path [#ibis.step<parent : !ibis.scoperef>]
  %some_child = ibis.path [#ibis.step<child , @a : !ibis.scoperef>]
```

I presume that correct behavior here would either be that a valid parser is generated or that the tablegen backend fails to generate a valid parser for the assembly format specified.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to