[clang] d34901f - Revert "[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)"
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 2 10:10:07 PST 2024
Author: Arthur Eubanks
Date: 2024-01-02T18:09:16Z
New Revision: d34901f30b8b7ac8fe1437eeb588da6805b27cfb
URL: https://github.com/llvm/llvm-project/commit/d34901f30b8b7ac8fe1437eeb588da6805b27cfb
DIFF: https://github.com/llvm/llvm-project/commit/d34901f30b8b7ac8fe1437eeb588da6805b27cfb.diff
LOG: Revert "[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)"
This reverts commit 61999b18c407b9f5c07577e63057d41c65240e61.
See comments on https://github.com/llvm/llvm-project/pull/75841. This
was intended to be NFC but actually isn't.
Added:
clang/test/Preprocessor/cuda-macos-includes.cu
Modified:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Lex/InitHeaderSearch.cpp
clang/test/Driver/driverkit-path.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index f76a42d2d8e7e3..65846cace461e3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -758,14 +758,9 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
- // Add framework include paths and library search paths.
- // There are two flavors:
- // 1. The "non-standard" paths, e.g. for DriverKit:
- // -L<sysroot>/System/DriverKit/usr/lib
- // -F<sysroot>/System/DriverKit/System/Library/Frameworks
- // 2. The "standard" paths, e.g. for macOS and iOS:
- // -F<sysroot>/System/Library/Frameworks
- // -F<sysroot>/Library/Frameworks
+ // Add non-standard, platform-specific search paths, e.g., for DriverKit:
+ // -L<sysroot>/System/DriverKit/usr/lib
+ // -F<sysroot>/System/DriverKit/System/Library/Framework
{
bool NonStandardSearchPath = false;
const auto &Triple = getToolChain().getTriple();
@@ -776,22 +771,18 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
(Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1);
}
- if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
- auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
- SmallString<128> P(Sysroot->getValue());
- AppendPlatformPrefix(P, Triple);
- llvm::sys::path::append(P, SearchPath);
- if (getToolChain().getVFS().exists(P)) {
- CmdArgs.push_back(Args.MakeArgString(Flag + P));
- }
- };
-
- if (NonStandardSearchPath) {
+ if (NonStandardSearchPath) {
+ if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
+ auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
+ SmallString<128> P(Sysroot->getValue());
+ AppendPlatformPrefix(P, Triple);
+ llvm::sys::path::append(P, SearchPath);
+ if (getToolChain().getVFS().exists(P)) {
+ CmdArgs.push_back(Args.MakeArgString(Flag + P));
+ }
+ };
AddSearchPath("-L", "/usr/lib");
AddSearchPath("-F", "/System/Library/Frameworks");
- } else if (!Triple.isDriverKit()) {
- AddSearchPath("-F", "/System/Library/Frameworks");
- AddSearchPath("-F", "/Library/Frameworks");
}
}
}
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index 1350fa5f01a578..2218db15013d92 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -324,9 +324,6 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
break;
}
- if (triple.isOSDarwin())
- return false;
-
return true; // Everything else uses AddDefaultIncludePaths().
}
@@ -341,6 +338,21 @@ void InitHeaderSearch::AddDefaultIncludePaths(
if (!ShouldAddDefaultIncludePaths(triple))
return;
+ // NOTE: some additional header search logic is handled in the driver for
+ // Darwin.
+ if (triple.isOSDarwin()) {
+ if (HSOpts.UseStandardSystemIncludes) {
+ // Add the default framework include paths on Darwin.
+ if (triple.isDriverKit()) {
+ AddPath("/System/DriverKit/System/Library/Frameworks", System, true);
+ } else {
+ AddPath("/System/Library/Frameworks", System, true);
+ AddPath("/Library/Frameworks", System, true);
+ }
+ }
+ return;
+ }
+
if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
if (HSOpts.UseLibcxx) {
diff --git a/clang/test/Driver/driverkit-path.c b/clang/test/Driver/driverkit-path.c
index 43e5aa40fc6f31..9699b9c01f4e81 100644
--- a/clang/test/Driver/driverkit-path.c
+++ b/clang/test/Driver/driverkit-path.c
@@ -31,3 +31,4 @@ int main() { return 0; }
// INC: [[PATH]]/System/DriverKit/usr/local/include
// INC: /lib{{(64)?}}/clang/{{[^/ ]+}}/include
// INC: [[PATH]]/System/DriverKit/usr/include
+// INC: [[PATH]]/System/DriverKit/System/Library/Frameworks (framework directory)
diff --git a/clang/test/Preprocessor/cuda-macos-includes.cu b/clang/test/Preprocessor/cuda-macos-includes.cu
new file mode 100644
index 00000000000000..6ef94b0e453520
--- /dev/null
+++ b/clang/test/Preprocessor/cuda-macos-includes.cu
@@ -0,0 +1,13 @@
+// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
+// RUN: -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
+// RUN: -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// RUN: %clang -cc1 -isysroot /var/empty \
+// RUN: -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
+// RUN: -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
+
+// Check that when we do CUDA host and device compiles on MacOS, we check for
+// includes in /System/Library/Frameworks and /Library/Frameworks.
+
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/System/Library/Frameworks"
+// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks"
More information about the cfe-commits
mailing list