[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-09 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbab9849963eb: Reland 198fbcb8, Driver: Dont look 
for libc++ headers in the install… (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D71154?vs=232683=232892#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/android-no-installed-libcxx.cpp
  clang/test/Driver/stdlibxx-isystem.cpp

Index: clang/test/Driver/stdlibxx-isystem.cpp
===
--- clang/test/Driver/stdlibxx-isystem.cpp
+++ clang/test/Driver/stdlibxx-isystem.cpp
@@ -6,7 +6,7 @@
 // By default, we should search for libc++ next to the driver.
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/include/c++/v1
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=LIBCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
 // LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // Passing -stdlib++-isystem should suppress the default search.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NODEFAULT %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -26,7 +26,7 @@
 // NODEFAULT-NOT: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // And we should add it as an -internal-isystem.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=INCPATH %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -35,7 +35,7 @@
 // INCPATH: "-internal-isystem" "/tmp/foo" "-internal-isystem" "/tmp/bar"
 
 // We shouldn't pass the -stdlib++-isystem to cc1.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=NOCC1 %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -44,7 +44,7 @@
 // NOCC1-NOT: "-stdlib++-isystem" "/tmp"
 
 // It should respect -nostdinc++.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
Index: clang/test/Driver/android-no-installed-libcxx.cpp
===
--- /dev/null
+++ clang/test/Driver/android-no-installed-libcxx.cpp
@@ -0,0 +1,10 @@
+// Check that we don't find the libc++ in the installation directory when
+// targeting Android.
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/include/c++/v1
+// RUN: mkdir -p %t/sysroot
+// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN:   --sysroot=%t/sysroot -stdlib=libc++ -fsyntax-only \
+// RUN:   %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -888,20 +888,25 @@
 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
   const std::string& SysRoot = computeSysRoot();
-  const std::string LibCXXIncludePathCandidates[] = {
-  DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/include/c++") };
-  for (const auto  : LibCXXIncludePathCandidates) {
+  auto AddIncludePath = [&](std::string Path) {
+std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
 if (IncludePath.empty() || !getVFS().exists(IncludePath))
-  continue;
-// Use the first candidate that exists.
+  return 

[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-09 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc reopened this revision.
pcc added a comment.
This revision is now accepted and ready to land.

Relanding with a fix for the problem found by @davezarzycki. The test needed to 
be adjusted to set `--sysroot`, otherwise it will fail in the case where a 
directory named `/usr/include/c++/v1` or `/usr/local/include/c++/v1` exists.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-08 Thread David Zarzycki via Phabricator via cfe-commits
davezarzycki added a comment.

Sorry, I had to revert this for breaking things. Please ping me when you have a 
new patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-07 Thread David Zarzycki via Phabricator via cfe-commits
davezarzycki added a comment.

Can we revert this? It doesn't seem to work on my Fedora 31 box:

  FAIL: Clang :: Driver/android-no-installed-libcxx.cpp (9249 of 59761)
   TEST 'Clang :: Driver/android-no-installed-libcxx.cpp' 
FAILED 
  Script:
  --
  : 'RUN: at line 4';   mkdir -p 
/tmp/_update_lc/r/tools/clang/test/Driver/Output/android-no-installed-libcxx.cpp.tmp/bin
  : 'RUN: at line 5';   mkdir -p 
/tmp/_update_lc/r/tools/clang/test/Driver/Output/android-no-installed-libcxx.cpp.tmp/include/c++/v1
  : 'RUN: at line 6';   /tmp/_update_lc/r/bin/clang -target 
aarch64-linux-android -ccc-install-dir 
/tmp/_update_lc/r/tools/clang/test/Driver/Output/android-no-installed-libcxx.cpp.tmp/bin
-stdlib=libc++ -fsyntax-only 
/home/dave/s/lp/clang/test/Driver/android-no-installed-libcxx.cpp -### 2>&1 | 
/tmp/_update_lc/r/bin/FileCheck 
/home/dave/s/lp/clang/test/Driver/android-no-installed-libcxx.cpp
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  /home/dave/s/lp/clang/test/Driver/android-no-installed-libcxx.cpp:8:15: 
error: CHECK-NOT: excluded string found in input
  // CHECK-NOT: "-internal-isystem" "{{.*}}v1"
^
  :5:653: note: found here
   "/tmp/_update_lc/r/bin/clang-10" "-cc1" "-triple" 
"aarch64-unknown-linux-android" "-fsyntax-only" "-disable-free" 
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" 
"android-no-installed-libcxx.cpp" "-mrelocation-model" "pic" "-pic-level" "2" 
"-pic-is-pie" "-mthread-model" "posix" "-mframe-pointer=all" 
"-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-fuse-init-array" 
"-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" 
"-mllvm" "-aarch64-fix-cortex-a53-835769=1" 
"-fallow-half-arguments-and-returns" "-dwarf-column-info" 
"-debugger-tuning=gdb" "-resource-dir" "/tmp/_update_lc/r/lib64/clang/10.0.0" 
"-internal-isystem" "/usr/include/c++/v1" "-internal-isystem" 
"/usr/local/include" "-internal-isystem" 
"/tmp/_update_lc/r/lib64/clang/10.0.0/include" "-internal-externc-isystem" 
"/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" 
"-fdebug-compilation-dir" "/tmp/_update_lc/r/tools/clang/test/Driver" 
"-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" 
"-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" 
"-fdiagnostics-show-option" "-x" "c++" 
"/home/dave/s/lp/clang/test/Driver/android-no-installed-libcxx.cpp"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG198fbcb81749: Driver: Dont look for libc++ headers in 
the install directory on Android. (authored by pcc).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/android-no-installed-libcxx.cpp
  clang/test/Driver/stdlibxx-isystem.cpp

Index: clang/test/Driver/stdlibxx-isystem.cpp
===
--- clang/test/Driver/stdlibxx-isystem.cpp
+++ clang/test/Driver/stdlibxx-isystem.cpp
@@ -6,7 +6,7 @@
 // By default, we should search for libc++ next to the driver.
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/include/c++/v1
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=LIBCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
 // LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // Passing -stdlib++-isystem should suppress the default search.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NODEFAULT %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -26,7 +26,7 @@
 // NODEFAULT-NOT: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // And we should add it as an -internal-isystem.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=INCPATH %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -35,7 +35,7 @@
 // INCPATH: "-internal-isystem" "/tmp/foo" "-internal-isystem" "/tmp/bar"
 
 // We shouldn't pass the -stdlib++-isystem to cc1.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=NOCC1 %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -44,7 +44,7 @@
 // NOCC1-NOT: "-stdlib++-isystem" "/tmp"
 
 // It should respect -nostdinc++.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
Index: clang/test/Driver/android-no-installed-libcxx.cpp
===
--- /dev/null
+++ clang/test/Driver/android-no-installed-libcxx.cpp
@@ -0,0 +1,8 @@
+// Check that we don't find the libc++ in the installation directory when
+// targeting Android.
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/include/c++/v1
+// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -888,20 +888,25 @@
 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
   const std::string& SysRoot = computeSysRoot();
-  const std::string LibCXXIncludePathCandidates[] = {
-  DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/include/c++") };
-  for (const auto  : LibCXXIncludePathCandidates) {
+  auto AddIncludePath = [&](std::string Path) {
+std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
 if (IncludePath.empty() || !getVFS().exists(IncludePath))
-  continue;
-// Use the first candidate that exists.
+  return false;
 addSystemInclude(DriverArgs, CC1Args, IncludePath);
+return true;
+  };
+  // Android never uses the libc++ headers installed 

[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Dan Albert via Phabricator via cfe-commits
danalbert accepted this revision.
danalbert added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/Driver/android-no-installed-libcxx.cpp:8
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

pcc wrote:
> danalbert wrote:
> > This looks like it should be failing. The NDK headers are installed to 
> > `/sysroot/usr/include/c++/v1`. Presumably it's passing because the 
> > trivial sysroot in the test directory is not complete enough?
> > 
> > Will need a more specific CHECK-NOT here, and also a CHECK to make sure the 
> > correct directory is being searched.
> The `%t/include/c++/v1` path here represents the install directory, not the 
> sysroot. Note that the test isn't passing a `-sysroot` flag.
> 
> We already have a test that the correct directory is being searched, see 
> `test/Driver/android-ndk-standalone.cpp`.
Ah, I'd forgotten that the tests required an explicit `--sysroot` flag. That's 
not required for a typical NDK clang call, but it is here. Never mind then, 
this LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc marked an inline comment as done.
pcc added inline comments.



Comment at: clang/test/Driver/android-no-installed-libcxx.cpp:8
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

danalbert wrote:
> This looks like it should be failing. The NDK headers are installed to 
> `/sysroot/usr/include/c++/v1`. Presumably it's passing because the 
> trivial sysroot in the test directory is not complete enough?
> 
> Will need a more specific CHECK-NOT here, and also a CHECK to make sure the 
> correct directory is being searched.
The `%t/include/c++/v1` path here represents the install directory, not the 
sysroot. Note that the test isn't passing a `-sysroot` flag.

We already have a test that the correct directory is being searched, see 
`test/Driver/android-ndk-standalone.cpp`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Dan Albert via Phabricator via cfe-commits
danalbert requested changes to this revision.
danalbert added inline comments.
This revision now requires changes to proceed.



Comment at: clang/test/Driver/android-no-installed-libcxx.cpp:8
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"

This looks like it should be failing. The NDK headers are installed to 
`/sysroot/usr/include/c++/v1`. Presumably it's passing because the trivial 
sysroot in the test directory is not complete enough?

Will need a more specific CHECK-NOT here, and also a CHECK to make sure the 
correct directory is being searched.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

Build result: pass - 60573 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt 
,
 CMakeCache.txt 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71154/new/

https://reviews.llvm.org/D71154



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71154: Driver: Don't look for libc++ headers in the install directory on Android.

2019-12-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
pcc added reviewers: danalbert, srhines.
Herald added a reviewer: EricWF.
Herald added a subscriber: ldionne.
Herald added a project: clang.

The NDK uses a separate set of libc++ headers in the sysroot. Any headers
in the installation directory are not going to work on Android, not least
because they use a different name for the inline namespace (std::__1 instead
of std::__ndk1).

This effectively makes it impossible to produce a single toolchain that is
capable of targeting both Android and another platform that expects libc++
headers to be installed in the installation directory, such as Mac.

In order to allow this scenario to work, stop looking for headers in the
install directory on Android.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71154

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/android-no-installed-libcxx.cpp
  clang/test/Driver/stdlibxx-isystem.cpp

Index: clang/test/Driver/stdlibxx-isystem.cpp
===
--- clang/test/Driver/stdlibxx-isystem.cpp
+++ clang/test/Driver/stdlibxx-isystem.cpp
@@ -6,7 +6,7 @@
 // By default, we should search for libc++ next to the driver.
 // RUN: mkdir -p %t/bin
 // RUN: mkdir -p %t/include/c++/v1
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=LIBCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -16,7 +16,7 @@
 // LIBCXX: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // Passing -stdlib++-isystem should suppress the default search.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NODEFAULT %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -26,7 +26,7 @@
 // NODEFAULT-NOT: "-internal-isystem" "[[INSTALLDIR]]/../include/c++/v1"
 
 // And we should add it as an -internal-isystem.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -stdlib=libc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=INCPATH %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -35,7 +35,7 @@
 // INCPATH: "-internal-isystem" "/tmp/foo" "-internal-isystem" "/tmp/bar"
 
 // We shouldn't pass the -stdlib++-isystem to cc1.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp -stdlib=libc++ -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck -check-prefix=NOCC1 %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
@@ -44,7 +44,7 @@
 // NOCC1-NOT: "-stdlib++-isystem" "/tmp"
 
 // It should respect -nostdinc++.
-// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN: %clang -target aarch64-linux-gnu -ccc-install-dir %t/bin \
 // RUN:   -stdlib++-isystem /tmp/foo -stdlib++-isystem /tmp/bar -nostdinc++ \
 // RUN:   -fsyntax-only %s -### 2>&1 | FileCheck -check-prefix=NOSTDINCXX %s
 // RUN: %clang -target x86_64-apple-darwin -ccc-install-dir %t/bin \
Index: clang/test/Driver/android-no-installed-libcxx.cpp
===
--- /dev/null
+++ clang/test/Driver/android-no-installed-libcxx.cpp
@@ -0,0 +1,8 @@
+// Check that we don't find the libc++ in the installation directory when
+// targeting Android.
+
+// RUN: mkdir -p %t/bin
+// RUN: mkdir -p %t/include/c++/v1
+// RUN: %clang -target aarch64-linux-android -ccc-install-dir %t/bin \
+// RUN:   -stdlib=libc++ -fsyntax-only %s -### 2>&1 | FileCheck %s
+// CHECK-NOT: "-internal-isystem" "{{.*}}v1"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -888,20 +888,25 @@
 void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const {
   const std::string& SysRoot = computeSysRoot();
-  const std::string LibCXXIncludePathCandidates[] = {
-  DetectLibcxxIncludePath(getVFS(), getDriver().Dir + "/../include/c++"),
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  DetectLibcxxIncludePath(getVFS(), SysRoot + "/usr/local/include/c++"),
-  DetectLibcxxIncludePath(getVFS(), SysRoot +