[PATCH] D45814: Fix an assertion when -print-prog-name=

Christian Bruel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 27 05:54:43 PDT 2018


chrib updated this revision to Diff 144322.
chrib added a comment.

Move the non-null name check out of GetProgramPath and add a test case.

Assume that we trust the callers to check for non null ProgramName.


Repository:
  rC Clang

https://reviews.llvm.org/D45814

Files:
  lib/Driver/Driver.cpp
  test/Driver/print-empty-prog-name.c


Index: test/Driver/print-empty-prog-name.c
===================================================================
--- /dev/null
+++ test/Driver/print-empty-prog-name.c
@@ -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:{{.+}}
+
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1589,7 +1589,13 @@
   }
 
   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;
   }
 
@@ -4053,6 +4059,7 @@
 }
 
 std::string Driver::GetProgramPath(StringRef Name, const ToolChain &TC) const {
+
   SmallVector<std::string, 2> TargetSpecificExecutables;
   generatePrefixedToolNames(Name, TC, TargetSpecificExecutables);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45814.144322.patch
Type: text/x-patch
Size: 1107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180427/86d10281/attachment.bin>


More information about the cfe-commits mailing list