[PATCH] D157283: [clang] Match -isysroot behaviour with system compiler on Darwin
Dmitry Polukhin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 07:11:16 PDT 2023
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: ldionne, dexonsmith, MaskRay.
DmitryPolukhin added a project: clang.
Herald added a project: All.
DmitryPolukhin requested review of this revision.
Herald added a subscriber: cfe-commits.
See discussion in https://reviews.llvm.org/D89001
I updated test to match actual behavior of
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
after that modified upstream to match the test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157283
Files:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-header-search-libcxx.cpp
Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===================================================================
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -89,8 +89,8 @@
// RUN: --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
//
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the toolchain
// C++ include path and the sysroot one.
@@ -104,9 +104,9 @@
// RUN: -nostdinc \
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
-// RUN: --check-prefix=CHECK-LIBCXX-NOSTDLIBINC %s
+// RUN: --check-prefix=CHECK-LIBCXX-NOSTDINC %s
// CHECK-LIBCXX-NOSTDINC: "-cc1"
-// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
+// CHECK-LIBCXX-NOSTDINC: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
// CHECK-LIBCXX-NOSTDINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
//
// RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -157,8 +157,8 @@
// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \
// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
// RUN: --check-prefix=CHECK-LIBCXX-MISSING-BOTH %s
-// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-MISSING-BOTH: ignoring nonexistent directory "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
// Make sure that on Darwin, we use libc++ header search paths by default even when
// -stdlib= isn't passed.
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2463,8 +2463,7 @@
// Also check whether this is used for setting library search paths.
ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
- if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
- options::OPT_nostdincxx))
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdincxx))
return;
llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs);
@@ -2472,8 +2471,8 @@
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx: {
// On Darwin, libc++ can be installed in one of the following two places:
- // 1. Alongside the compiler in <install>/include/c++/v1
- // 2. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
+ // 1. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
+ // 2. Alongside the compiler in <install>/include/c++/v1
//
// The precendence of paths is as listed above, i.e. we take the first path
// that exists. Also note that we never include libc++ twice -- we take the
@@ -2481,6 +2480,17 @@
// include_next could break).
// Check for (1)
+ llvm::SmallString<128> SysrootUsr = Sysroot;
+ llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+ if (getVFS().exists(SysrootUsr)) {
+ addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+ return;
+ } else if (DriverArgs.hasArg(options::OPT_v)) {
+ llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+ << "\"\n";
+ }
+
+ // Otherwise, check for (2)
// Get from '<install>/bin' to '<install>/include/c++/v1'.
// Note that InstallBin can be relative, so we use '..' instead of
// parent_path.
@@ -2495,17 +2505,6 @@
<< "\"\n";
}
- // Otherwise, check for (2)
- llvm::SmallString<128> SysrootUsr = Sysroot;
- llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
- if (getVFS().exists(SysrootUsr)) {
- addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
- return;
- } else if (DriverArgs.hasArg(options::OPT_v)) {
- llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
- << "\"\n";
- }
-
// Otherwise, don't add any path.
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157283.547776.patch
Type: text/x-patch
Size: 4754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230807/49d19dcd/attachment-0001.bin>
More information about the cfe-commits
mailing list