[PATCH] D154101: [MC] Add three-state parseDirective as a replacement for ParseDirective

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 11:34:42 PDT 2023


MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

> Conventionally, parsing methods return false on success and true on error. However, directive parsing methods need a third state: [...]

Agreed. Thanks for cleaning up this.

> ParseStatus is intentionally implicitly constructible from bool to allow uses like return Error(Loc, "message").

Nice!

> It also has a potential to replace OperandMatchResulTy as it is more convenient to use due to the implicit construction from bool and more type safe.

Agreed. It looks like `OperandMatchResulTy` could be named more generically to support `ParseStatus` does in this patch, but unfortunately this is difficult to change as the three enum members have 1000+ references...



================
Comment at: llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp:700
                                         AVRMCExpr::VK_AVR_None);
-    return false;
+    return ParseStatus::NoMatch;
   }
----------------
barannikov88 wrote:
> MaskRay wrote:
> > barannikov88 wrote:
> > > @benshi001
> > > There is something odd here. It handles cases like: `.word foo - bar`, emits some data, but then lets the generic parser handle the directive, which results in emitting more data. It also looks like this code path is not covered by object-emission tests. This was introduced in D38029.
> > > 
> > Thank your for noting this.
> > 
> > Side note: I find that many target AsmParser have poor test coverage, and we need some attention.
> I'll try to add a few tests by the end of the week
Thanks! I need to amend my comment. Many target AsmParser have poor test coverage for error conditions.

(For some targets (e.g. CSKY), I think many non-error-condition code paths are not covered.)
For future in-tree targets, I guess we should pay more attention on their test coverage..


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154101/new/

https://reviews.llvm.org/D154101



More information about the llvm-commits mailing list