OSDN Git Service

Let unaliased Args track which Alias they were created from, and use that in Arg...
authorNico Weber <nicolasweber@gmx.de>
Tue, 9 Jul 2019 00:34:08 +0000 (00:34 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 9 Jul 2019 00:34:08 +0000 (00:34 +0000)
commit4b3deaca421585217ab11aedc3ebeaf88c2591de
treec6a951a0f50b2549e84247eb632718236e2fed9c
parentdab869542b03a6911f74a836b7a3ad15c3407329
Let unaliased Args track which Alias they were created from, and use that in Arg::getAsString() for diagnostics

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.)

Differential Revision: https://reviews.llvm.org/D64253

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365413 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Option/Arg.h
include/llvm/Option/Option.h
lib/Option/Arg.cpp
lib/Option/Option.cpp