diff options
author | Nico Weber <nicolasweber@gmx.de> | 2019-07-05 11:28:31 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2019-07-05 11:28:31 +0000 |
commit | fdef18b42d02d69ca3a7be9c8c38a83ace51d9ff (patch) | |
tree | 2e421dc8b186b490db83f7d2595b0951e0c45e41 | |
parent | 433edaed127c16fd641d9515d1340a01086058ff (diff) | |
download | llvm-fdef18b42d02d69ca3a7be9c8c38a83ace51d9ff.zip llvm-fdef18b42d02d69ca3a7be9c8c38a83ace51d9ff.tar.gz llvm-fdef18b42d02d69ca3a7be9c8c38a83ace51d9ff.tar.bz2 |
lld-link: Make /debugtype: option work better
- The code tried to pass false to split()'s KeepEmpty parameter, but
instead passed it to MaxSplit. As a result, it would never split on
commas. This has been broken since the flag was added in r278056.
- The code used getSpelling() for getting the argument's values, but
getSpelling() always returns the `/debugtype:` prefix without any
values. So if any /debugtype: flag was passed, it always resulted in
an "unknown option:" warning. (The warning code then used the correct
getValue() for printing the invalid option, so the warning looked
kind of like it made sense.) This regressed in r342894.
Slightly improve the test coverage of this feature (but since I don't
know what this flag actually does, there's still no test for the correct
semantics), and add a comment to getSpelling() explaining what it does.
llvm-svn: 365182
-rw-r--r-- | lld/COFF/Driver.cpp | 5 | ||||
-rw-r--r-- | lld/test/COFF/invalid-debug-type.test | 11 | ||||
-rw-r--r-- | llvm/include/llvm/Option/Arg.h | 8 |
3 files changed, 19 insertions, 5 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index c1520a4..413b1e7 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -642,7 +642,8 @@ static unsigned parseDebugTypes(const opt::InputArgList &Args) { if (auto *A = Args.getLastArg(OPT_debugtype)) { SmallVector<StringRef, 3> Types; - A->getSpelling().split(Types, ',', /*KeepEmpty=*/false); + StringRef(A->getValue()) + .split(Types, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false); for (StringRef Type : Types) { unsigned V = StringSwitch<unsigned>(Type.lower()) @@ -651,7 +652,7 @@ static unsigned parseDebugTypes(const opt::InputArgList &Args) { .Case("fixup", static_cast<unsigned>(DebugType::Fixup)) .Default(0); if (V == 0) { - warn("/debugtype: unknown option: " + Twine(A->getValue())); + warn("/debugtype: unknown option '" + Type + "'"); continue; } DebugTypes |= V; diff --git a/lld/test/COFF/invalid-debug-type.test b/lld/test/COFF/invalid-debug-type.test index 0fa40b0..de6add7 100644 --- a/lld/test/COFF/invalid-debug-type.test +++ b/lld/test/COFF/invalid-debug-type.test @@ -1,6 +1,11 @@ # RUN: yaml2obj < %p/Inputs/pdb1.yaml > %t1.obj # RUN: yaml2obj < %p/Inputs/pdb2.yaml > %t2.obj -# RUN: lld-link /debug /debugtype:invalid /pdb:%t.pdb /dll /out:%t.dll /entry:main /nodefaultlib \ -# RUN: %t1.obj %t2.obj 2>&1 | FileCheck %s +# RUN: lld-link /debug /debugtype:invalid /pdb:%t.pdb /dll /out:%t.dll \ +# RUN: /entry:main /nodefaultlib %t1.obj %t2.obj 2>&1 | FileCheck %s +# CHECK: /debugtype: unknown option 'invalid' -# CHECK: /debugtype: unknown option: invalid
\ No newline at end of file +# RUN: lld-link /debug /debugtype:invalid,foo /pdb:%t.pdb /dll /out:%t.dll \ +# RUN: /entry:main /nodefaultlib %t1.obj %t2.obj 2>&1 | \ +# RUN: FileCheck --check-prefix=TWO %s +# TWO: /debugtype: unknown option 'invalid' +# TWO: /debugtype: unknown option 'foo' diff --git a/llvm/include/llvm/Option/Arg.h b/llvm/include/llvm/Option/Arg.h index d3623a0..8c47870 100644 --- a/llvm/include/llvm/Option/Arg.h +++ b/llvm/include/llvm/Option/Arg.h @@ -70,7 +70,15 @@ public: ~Arg(); const Option &getOption() const { return Opt; } + + /// Returns the used prefix and name of the option: + /// For `--foo=bar`, returns `--foo=`. + /// This is often the wrong function to call: + /// * Use `getValue()` to get `bar`. + /// * Use `getAsString()` to get a string suitable for printing an Arg in + /// a diagnostic. StringRef getSpelling() const { return Spelling; } + unsigned getIndex() const { return Index; } /// Return the base argument which generated this arg. |