]> granicus.if.org Git - clang/commitdiff
[Driver] Verify GCCInstallation is valid
authorNick Desaulniers <ndesaulniers@google.com>
Tue, 21 May 2019 21:21:35 +0000 (21:21 +0000)
committerNick Desaulniers <ndesaulniers@google.com>
Tue, 21 May 2019 21:21:35 +0000 (21:21 +0000)
Summary:
Values returned by GCCInstallation.getParentLibPath() and
GCCInstallation.getTriple() are not valid unless
GCCInstallation.isValid() returns true. This has previously been
ignored, and the former two values were used without checking whether
GCCInstallation is valid. This led to the bad path "/../bin" being added
to the list of program paths.

author: danielmentz "Daniel Mentz <danielmentz@google.com>"

Reviewers: #clang, tstellar, srhines

Reviewed By: srhines

Subscribers: danielmentz, ormris, nickdesaulniers, srhines, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57930

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361314 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Linux.cpp
test/Driver/B-opt.c

index e9169e91fd43a95255c3cf403de023272c5ef94f..4890ef457531542c7bee7b5b6cb54e3eba98b07b 100644 (file)
@@ -234,9 +234,11 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   // used to target i386.
   // FIXME: This seems unlikely to be Linux-specific.
   ToolChain::path_list &PPaths = getProgramPaths();
-  PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
-                         GCCInstallation.getTriple().str() + "/bin")
-                       .str());
+  if (GCCInstallation.isValid()) {
+    PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
+                           GCCInstallation.getTriple().str() + "/bin")
+                         .str());
+  }
 
   Distro Distro(D.getVFS());
 
index 51273fd7b8269ca1e9d5b7e47ac5a8cf252485ae..5e5ff42fd0956a7fabf55b3af65de3a792163516 100644 (file)
@@ -20,3 +20,8 @@
 // RUN:     -B %S/Inputs/B_opt_tree/dir2 2>&1 -fuse-ld=ld \
 // RUN:   | FileCheck --check-prefix=CHECK-B-OPT-MULT %s
 // CHECK-B-OPT-MULT: "{{.*}}/Inputs/B_opt_tree/dir3{{/|\\\\}}prefix-ld"
+//
+// RUN: %clang -B %S/Inputs/does_not_exist -print-search-dirs \
+// RUN:     -target aarch64-linux-gnu \
+// RUN:   | FileCheck --check-prefix=CHECK-B-OPT-INVALID %s
+// CHECK-B-OPT-INVALID-NOT: /..//bin