[PATCH] D64253: Let unaliased Args track which Alias they were created from, and use that in Arg::getAsString() for diagnostics

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 5 09:03:54 PDT 2019


thakis created this revision.
thakis added a reviewer: rnk.
Herald added subscribers: MaskRay, hiraditya, arichardson, javed.absar, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

With this, `clang-cl /source-charset:utf-16 test.cc` now prints `invalid value 'utf-16' in '/source-charset:utf-16'` instead of `invalid value 'utf-16' in '-finput-charset=utf-16'` before, and several other clang-cl flags produce much less confusing output as well.

Fixes PR29106.

Since an arg and its alias can have different arg types (joined vs not) and different values (because of AliasArgs<>), I chose to give the Alias its own Arg object. For convenience, I just store the alias directly in the unaliased arg – there aren't many arg objects at runtime, so that seems ok.

Finally, I changed Arg::getAsString() to use the alias's representation if it's present – that function was already documented as being the suitable function for diagnostics, and most callers already used it for diagnostics.

Implementation-wise, Arg::accept() previously used to parse things as the unaliased option. The core of that switch is now extracted into a new function acceptInternal() which parses as the _aliased_ option, and the previously-intermingled unaliasing is now done as an explicit step afterwards.

(This also changes one place in lld that didn't use getAsString() for diagnostics, so that that one place now also prints the flag as the user wrote it, not as it looks after it went through unaliasing.)


https://reviews.llvm.org/D64253

Files:
  clang/test/Driver/arm-execute-only.c
  clang/test/Driver/cl-options.c
  clang/test/Driver/darwin-version.c
  lld/Common/Reproduce.cpp
  lld/ELF/Driver.cpp
  lld/test/ELF/sectionstart.s
  llvm/include/llvm/Option/Arg.h
  llvm/include/llvm/Option/Option.h
  llvm/lib/Option/Arg.cpp
  llvm/lib/Option/Option.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64253.208192.patch
Type: text/x-patch
Size: 18661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190705/303f18ae/attachment-0001.bin>


More information about the cfe-commits mailing list