This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add support for regex within `expected-*` diagnostics
ClosedPublic

Authored by rriddle on Jul 7 2022, 7:59 PM.

Details

Summary

This can be enabled by using a -re suffix when defining the expected line,
e.g. expected-error-re. This support is similar to what clang provides in its "expected"
diagnostic framework(e.g. the -re is also the same). The regex definitions themselves are
similar to FileCheck in that regex blocks are specified within {{ }} blocks.

Diff Detail

Event Timeline

rriddle created this revision.Jul 7 2022, 7:59 PM
rriddle requested review of this revision.Jul 7 2022, 7:59 PM
rriddle updated this revision to Diff 443121.Jul 7 2022, 8:00 PM
jpienaar added inline comments.Jul 7 2022, 8:38 PM
mlir/docs/Diagnostics.md
306

Any reason to not follow filecheck? E.g., re is default and these are special tokens and you have literal matches with special tags. Is this due to outer delimiters being {{?

rriddle added inline comments.Jul 7 2022, 8:40 PM
mlir/docs/Diagnostics.md
306

My thoughts there were:

a) This follows the same precedent as clang/other tools
b) We'd need to rewrite many checks

Seemed better to follow the standard set by clang/other tools in llvm for the expected-* things, and also avoid unnecessary churn.

Agreed, following clang SGTM

mlir/lib/IR/Diagnostics.cpp
612

Nit: prefer positive conditional

625

Do you want to allow escaping too? E.g., if string has literal {{ and actual regex's ? (I see clang's VerifyDiagnosticConsumer doesn't either, and can be worked around with same trick as we do FileCheck side)

rriddle updated this revision to Diff 443306.Jul 8 2022, 11:32 AM
rriddle marked 2 inline comments as done.
rriddle added inline comments.Jul 8 2022, 11:32 AM
mlir/lib/IR/Diagnostics.cpp
625

We could, but I can't find any places right now where we would use it. I think if it becomes common enough, we could add something. It just doesn't look like it pays for itself right now (given that it has a workaround).

jpienaar accepted this revision.Jul 11 2022, 7:29 PM
This revision is now accepted and ready to land.Jul 11 2022, 7:29 PM