Skip to content

Commit

Permalink
[ms] llvm-lib gives a more useful error if no inputs and no output pa…
Browse files Browse the repository at this point in the history
…th 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
  • Loading branch information
ericastor committed May 1, 2020
1 parent 29b955f commit 1428f86
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1428f86

Please sign in to comment.