diff options
author | Eric Astor <epastor@google.com> | 2020-05-01 07:42:54 -0400 |
---|---|---|
committer | Eric Astor <epastor@google.com> | 2020-05-01 07:43:32 -0400 |
commit | 1428f86cf9863255adac92e82ae459331123a502 (patch) | |
tree | a52bc2138f3d66d82864113138eb2e1d7d02d6df /llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | |
parent | 29b955f97cc6a4b96aba0ccdc033884c51ef466f (diff) | |
download | llvm-1428f86cf9863255adac92e82ae459331123a502.zip llvm-1428f86cf9863255adac92e82ae459331123a502.tar.gz llvm-1428f86cf9863255adac92e82ae459331123a502.tar.bz2 |
[ms] llvm-lib gives a more useful error if no inputs and no output path are provided
Summary:
If no inputs and no output path are provided, llvm-lib should produce a useful error.
Before this, it would fail by reading from an unitialized StringRef.
Reviewed By: vvereschaka
Differential Revision: https://reviews.llvm.org/D79227
Diffstat (limited to 'llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp')
-rw-r--r-- | llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 69106bb..d622c16 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -59,10 +59,7 @@ public: } -static std::string getOutputPath(opt::InputArgList *Args, - const NewArchiveMember &FirstMember) { - if (auto *Arg = Args->getLastArg(OPT_out)) - return Arg->getValue(); +static std::string getDefaultOutputPath(const NewArchiveMember &FirstMember) { SmallString<128> Val = StringRef(FirstMember.Buf->getBufferIdentifier()); sys::path::replace_extension(Val, ".lib"); return std::string(Val.str()); @@ -353,7 +350,15 @@ int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) { } // Create an archive file. - std::string OutputPath = getOutputPath(&Args, Members[0]); + std::string OutputPath; + if (auto *Arg = Args.getLastArg(OPT_out)) { + OutputPath = Arg->getValue(); + } else if (!Members.empty()) { + OutputPath = getDefaultOutputPath(Members[0]); + } else { + llvm::errs() << "no output path given, and cannot infer with no inputs\n"; + return 1; + } // llvm-lib uses relative paths for both regular and thin archives, unlike // standard GNU ar, which only uses relative paths for thin archives and // basenames for regular archives. |