Skip to content

Commit 3197357

Browse files
committed
Revert "[clang] Match -isysroot behaviour with system compiler on Darwin"
This reverts commit f24aa69. This change caused these two test failures on Darwin CI: Clang.Tooling.clang-check-mac-libcxx-abspath.cpp Clang.Tooling.clang-check-mac-libcxx-relpath.cpp https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/37169/ More info in https://reviews.llvm.org/D157283
1 parent 979e8ae commit 3197357

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,34 +2465,24 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
24652465
// Also check whether this is used for setting library search paths.
24662466
ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
24672467

2468-
if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdincxx))
2468+
if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
2469+
options::OPT_nostdincxx))
24692470
return;
24702471

24712472
llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs);
24722473

24732474
switch (GetCXXStdlibType(DriverArgs)) {
24742475
case ToolChain::CST_Libcxx: {
24752476
// On Darwin, libc++ can be installed in one of the following two places:
2476-
// 1. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
2477-
// 2. Alongside the compiler in <install>/include/c++/v1
2477+
// 1. Alongside the compiler in <install>/include/c++/v1
2478+
// 2. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
24782479
//
24792480
// The precendence of paths is as listed above, i.e. we take the first path
24802481
// that exists. Also note that we never include libc++ twice -- we take the
24812482
// first path that exists and don't send the other paths to CC1 (otherwise
24822483
// include_next could break).
24832484

24842485
// Check for (1)
2485-
llvm::SmallString<128> SysrootUsr = Sysroot;
2486-
llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
2487-
if (getVFS().exists(SysrootUsr)) {
2488-
addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
2489-
return;
2490-
} else if (DriverArgs.hasArg(options::OPT_v)) {
2491-
llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
2492-
<< "\"\n";
2493-
}
2494-
2495-
// Otherwise, check for (2)
24962486
// Get from '<install>/bin' to '<install>/include/c++/v1'.
24972487
// Note that InstallBin can be relative, so we use '..' instead of
24982488
// parent_path.
@@ -2507,6 +2497,17 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
25072497
<< "\"\n";
25082498
}
25092499

2500+
// Otherwise, check for (2)
2501+
llvm::SmallString<128> SysrootUsr = Sysroot;
2502+
llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
2503+
if (getVFS().exists(SysrootUsr)) {
2504+
addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
2505+
return;
2506+
} else if (DriverArgs.hasArg(options::OPT_v)) {
2507+
llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
2508+
<< "\"\n";
2509+
}
2510+
25102511
// Otherwise, don't add any path.
25112512
break;
25122513
}

clang/test/Driver/darwin-header-search-libcxx.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
// CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
5454

5555
// Check with both headers in the sysroot and headers alongside the installation
56-
// (the <sysroot> headers should be preferred over the headers in the toolchain).
56+
// (the headers in the toolchain should be preferred over the <sysroot> headers).
5757
// Ensure that both -isysroot and --sysroot work, and that isysroot has precedence
5858
// over --sysroot.
5959
//
@@ -89,10 +89,10 @@
8989
// RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
9090
//
9191
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1"
92-
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
93-
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
92+
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
93+
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
9494

95-
// Make sure that using -nostdinc++ or -nostdlib will drop both the toolchain
95+
// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the toolchain
9696
// C++ include path and the sysroot one.
9797
//
9898
// RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -104,9 +104,9 @@
104104
// RUN: -nostdinc \
105105
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
106106
// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
107-
// RUN: --check-prefix=CHECK-LIBCXX-NOSTDINC %s
107+
// RUN: --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s
108108
// CHECK-LIBCXX-NOSTDINC: "-cc1"
109-
// CHECK-LIBCXX-NOSTDINC: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
109+
// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
110110
// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
111111
//
112112
// RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -157,8 +157,8 @@
157157
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \
158158
// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
159159
// RUN: --check-prefix=CHECK-LIBCXX-MISSING-BOTH %s
160-
// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[SYSROOT]]/usr/include/c++/v1"
161160
// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
161+
// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[SYSROOT]]/usr/include/c++/v1"
162162

163163
// Make sure that on Darwin, we use libc++ header search paths by default even when
164164
// -stdlib= isn't passed.

0 commit comments

Comments
 (0)