[Driver] Verify GCCInstallation is valid

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

llvm-svn: 361314
This commit is contained in:
Nick Desaulniers 2019-05-21 21:21:35 +00:00
parent df17ddf9fc
commit 17694af980
2 changed files with 10 additions and 3 deletions

View 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());

View 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