[llvm] 1428f86 - [ms] llvm-lib gives a more useful error if no inputs and no output path are provided
Eric Astor via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 04:44:17 PDT 2020
Author: Eric Astor
Date: 2020-05-01T07:43:32-04:00
New Revision: 1428f86cf9863255adac92e82ae459331123a502
URL: https://github.com/llvm/llvm-project/commit/1428f86cf9863255adac92e82ae459331123a502
DIFF: https://github.com/llvm/llvm-project/commit/1428f86cf9863255adac92e82ae459331123a502.diff
LOG: [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
Added:
Modified:
llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
index 69106bbeac21..d622c1672203 100644
--- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -59,10 +59,7 @@ class LibOptTable : public opt::OptTable {
}
-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.
More information about the llvm-commits
mailing list