From e9f666dff4764e65704d0145c35d57a7467d8e51 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 21 May 2019 21:21:35 +0000 Subject: [PATCH] [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 " 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 | 8 +++++--- test/Driver/B-opt.c | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp index e9169e91fd..4890ef4575 100644 --- a/lib/Driver/ToolChains/Linux.cpp +++ b/lib/Driver/ToolChains/Linux.cpp @@ -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()); diff --git a/test/Driver/B-opt.c b/test/Driver/B-opt.c index 51273fd7b8..5e5ff42fd0 100644 --- a/test/Driver/B-opt.c +++ b/test/Driver/B-opt.c @@ -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 -- 2.50.1