Driver: fix an assertion with `-print-prog-name=`

Fix an assertion when -print-prog-name= is invoked without parameter.
Returns an empty string.

Patch by Christian Bruel!

llvm-svn: 331296
This commit is contained in:
Saleem Abdulrasool 2018-05-01 18:40:42 +00:00
parent e8e95b5b01
commit e5f3cf824f
2 changed files with 12 additions and 1 deletions

View File

@ -1594,7 +1594,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
}
if (Arg *A = C.getArgs().getLastArg(options::OPT_print_prog_name_EQ)) {
llvm::outs() << GetProgramPath(A->getValue(), TC) << "\n";
StringRef ProgName = A->getValue();
// Null program name cannot have a path.
if (! ProgName.empty())
llvm::outs() << GetProgramPath(ProgName, TC);
llvm::outs() << "\n";
return false;
}

View File

@ -0,0 +1,5 @@
// Test that -print-prog-name= correctly returns an empty string
// RUN: %clang -print-prog-name= 2>&1 | FileCheck %s
// CHECK-NOT:{{.+}}