[lld] r365413 - Let unaliased Args track which Alias they were created from, and use that in Arg::getAsString() for diagnostics
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 17:34:08 PDT 2019
Author: nico
Date: Mon Jul 8 17:34:08 2019
New Revision: 365413
URL: http://llvm.org/viewvc/llvm-project?rev=365413&view=rev
Log:
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
Modified:
lld/trunk/Common/Reproduce.cpp
lld/trunk/ELF/Driver.cpp
lld/trunk/test/ELF/sectionstart.s
Modified: lld/trunk/Common/Reproduce.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/Reproduce.cpp?rev=365413&r1=365412&r2=365413&view=diff
==============================================================================
--- lld/trunk/Common/Reproduce.cpp (original)
+++ lld/trunk/Common/Reproduce.cpp Mon Jul 8 17:34:08 2019
@@ -48,6 +48,8 @@ std::string lld::quote(StringRef S) {
return S;
}
+// Converts an Arg to a string representation suitable for a response file.
+// To show an Arg in a diagnostic, use Arg::getAsString() instead.
std::string lld::toString(const opt::Arg &Arg) {
std::string K = Arg.getSpelling();
if (Arg.getNumValues() == 0)
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=365413&r1=365412&r2=365413&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Jul 8 17:34:08 2019
@@ -588,12 +588,13 @@ static StripPolicy getStrip(opt::InputAr
return StripPolicy::Debug;
}
-static uint64_t parseSectionAddress(StringRef S, const opt::Arg &Arg) {
+static uint64_t parseSectionAddress(StringRef S, opt::InputArgList &Args,
+ const opt::Arg &Arg) {
uint64_t VA = 0;
if (S.startswith("0x"))
S = S.drop_front(2);
if (!to_integer(S, VA, 16))
- error("invalid argument: " + toString(Arg));
+ error("invalid argument: " + Arg.getAsString(Args));
return VA;
}
@@ -603,15 +604,15 @@ static StringMap<uint64_t> getSectionSta
StringRef Name;
StringRef Addr;
std::tie(Name, Addr) = StringRef(Arg->getValue()).split('=');
- Ret[Name] = parseSectionAddress(Addr, *Arg);
+ Ret[Name] = parseSectionAddress(Addr, Args, *Arg);
}
if (auto *Arg = Args.getLastArg(OPT_Ttext))
- Ret[".text"] = parseSectionAddress(Arg->getValue(), *Arg);
+ Ret[".text"] = parseSectionAddress(Arg->getValue(), Args, *Arg);
if (auto *Arg = Args.getLastArg(OPT_Tdata))
- Ret[".data"] = parseSectionAddress(Arg->getValue(), *Arg);
+ Ret[".data"] = parseSectionAddress(Arg->getValue(), Args, *Arg);
if (auto *Arg = Args.getLastArg(OPT_Tbss))
- Ret[".bss"] = parseSectionAddress(Arg->getValue(), *Arg);
+ Ret[".bss"] = parseSectionAddress(Arg->getValue(), Args, *Arg);
return Ret;
}
Modified: lld/trunk/test/ELF/sectionstart.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/sectionstart.s?rev=365413&r1=365412&r2=365413&view=diff
==============================================================================
--- lld/trunk/test/ELF/sectionstart.s (original)
+++ lld/trunk/test/ELF/sectionstart.s Mon Jul 8 17:34:08 2019
@@ -45,15 +45,15 @@
# RUN: not ld.lld %t.o -Ttext=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR3 %s
-# ERR3: invalid argument: --Ttext 1w0000
+# ERR3: invalid argument: -Ttext=1w0000
# RUN: not ld.lld %t.o -Tbss=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR4 %s
-# ERR4: invalid argument: --Tbss 1w0000
+# ERR4: invalid argument: -Tbss=1w0000
# RUN: not ld.lld %t.o -Tdata=1w0000 -o %t6 2>&1 \
# RUN: | FileCheck -check-prefix=ERR5 %s
-# ERR5: invalid argument: --Tdata 1w0000
+# ERR5: invalid argument: -Tdata=1w0000
.text
.globl _start
More information about the llvm-commits
mailing list