[PATCH] D79227: [ms] llvm-lib gives a more useful error if no inputs and no output path are provided
Eric Astor via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 20:23:56 PDT 2020
epastor created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
epastor added reviewers: vvereschaka, thakis.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79227
Files:
llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===================================================================
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -59,10 +59,7 @@
}
-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 @@
}
// 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79227.261425.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200501/e5e7e135/attachment.bin>
More information about the llvm-commits
mailing list