forked from OSchip/llvm-project
[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
This commit is contained in:
parent
29b955f97c
commit
1428f86cf9
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue