This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Fix verification of attribute + colon type ambiguity
ClosedPublic

Authored by Mogball on May 11 2022, 8:16 PM.

Details

Summary

An attribute without a type builder followed by a colon in an assembly format is potentially ambiguous because the parser will read ahead to parse the colon-type and pass this as the type argument to the attribute's constructor.

However, the previous verifier that checks for this ambiguity erroneously produces an error in the case of

let assemblyFormat = "( `(` $attr `)` )? `:`";

This patch fixes the bug by implementing a checker that correctly handles all edge cases, including very strange assembly formats like:

let assemblyFormat = "( `(` $attr ) : (`>`)? attr-dict (`>` $a^) : (`<`)? `:`";

Diff Detail

Event Timeline

Mogball created this revision.May 11 2022, 8:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 8:17 PM
Mogball requested review of this revision.May 11 2022, 8:17 PM
Mogball updated this revision to Diff 428850.May 11 2022, 8:21 PM

add extra test case

rriddle added inline comments.May 11 2022, 8:30 PM
mlir/tools/mlir-tblgen/OpFormatGen.cpp
2360

Shouldn't we be checking optional elements as well?

$attr (`:` $foo^)?

Feels like we should diagnose this.

2453

Can you split this out into a separate function? This logic in this function is kind of hard to follow.

2517

Can you just early return from the other if and sink this to the bottom?

Mogball marked 2 inline comments as done.May 13 2022, 11:02 AM
Mogball added inline comments.
mlir/tools/mlir-tblgen/OpFormatGen.cpp
2360

Optional elements go away before calling into this function. See the comment on the function below.

2517

This just moved code. Let me drop it from this diff.

Mogball updated this revision to Diff 429372.May 13 2022, 3:40 PM
Mogball marked 3 inline comments as done.

simplify the implementation of the attribute-colon verifier and catch more cases

Mogball updated this revision to Diff 429837.May 16 2022, 1:37 PM

clang-format

rriddle accepted this revision.May 16 2022, 1:43 PM

Looks good. I think we can do some more generalizations of the verification though (doesn't have to be in this commit). There are various other ambiguities that it'd be nice if they were simple to add the core checks for (e.g. attr-dict next to a region).

This revision is now accepted and ready to land.May 16 2022, 1:43 PM

Oh yeah, I forgot about that one (and I think I filed that bug...).

This revision was landed with ongoing or failed builds.May 16 2022, 2:15 PM
This revision was automatically updated to reflect the committed changes.