Skip to content

Commit d34901f

Browse files
committed
Revert "[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)"
This reverts commit 61999b1. See comments on #75841. This was intended to be NFC but actually isn't.
1 parent ffd173b commit d34901f

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,9 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
758758
}
759759
}
760760

761-
// Add framework include paths and library search paths.
762-
// There are two flavors:
763-
// 1. The "non-standard" paths, e.g. for DriverKit:
764-
// -L<sysroot>/System/DriverKit/usr/lib
765-
// -F<sysroot>/System/DriverKit/System/Library/Frameworks
766-
// 2. The "standard" paths, e.g. for macOS and iOS:
767-
// -F<sysroot>/System/Library/Frameworks
768-
// -F<sysroot>/Library/Frameworks
761+
// Add non-standard, platform-specific search paths, e.g., for DriverKit:
762+
// -L<sysroot>/System/DriverKit/usr/lib
763+
// -F<sysroot>/System/DriverKit/System/Library/Framework
769764
{
770765
bool NonStandardSearchPath = false;
771766
const auto &Triple = getToolChain().getTriple();
@@ -776,22 +771,18 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
776771
(Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1);
777772
}
778773

779-
if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
780-
auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
781-
SmallString<128> P(Sysroot->getValue());
782-
AppendPlatformPrefix(P, Triple);
783-
llvm::sys::path::append(P, SearchPath);
784-
if (getToolChain().getVFS().exists(P)) {
785-
CmdArgs.push_back(Args.MakeArgString(Flag + P));
786-
}
787-
};
788-
789-
if (NonStandardSearchPath) {
774+
if (NonStandardSearchPath) {
775+
if (auto *Sysroot = Args.getLastArg(options::OPT_isysroot)) {
776+
auto AddSearchPath = [&](StringRef Flag, StringRef SearchPath) {
777+
SmallString<128> P(Sysroot->getValue());
778+
AppendPlatformPrefix(P, Triple);
779+
llvm::sys::path::append(P, SearchPath);
780+
if (getToolChain().getVFS().exists(P)) {
781+
CmdArgs.push_back(Args.MakeArgString(Flag + P));
782+
}
783+
};
790784
AddSearchPath("-L", "/usr/lib");
791785
AddSearchPath("-F", "/System/Library/Frameworks");
792-
} else if (!Triple.isDriverKit()) {
793-
AddSearchPath("-F", "/System/Library/Frameworks");
794-
AddSearchPath("-F", "/Library/Frameworks");
795786
}
796787
}
797788
}

clang/lib/Lex/InitHeaderSearch.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
324324
break;
325325
}
326326

327-
if (triple.isOSDarwin())
328-
return false;
329-
330327
return true; // Everything else uses AddDefaultIncludePaths().
331328
}
332329

@@ -341,6 +338,21 @@ void InitHeaderSearch::AddDefaultIncludePaths(
341338
if (!ShouldAddDefaultIncludePaths(triple))
342339
return;
343340

341+
// NOTE: some additional header search logic is handled in the driver for
342+
// Darwin.
343+
if (triple.isOSDarwin()) {
344+
if (HSOpts.UseStandardSystemIncludes) {
345+
// Add the default framework include paths on Darwin.
346+
if (triple.isDriverKit()) {
347+
AddPath("/System/DriverKit/System/Library/Frameworks", System, true);
348+
} else {
349+
AddPath("/System/Library/Frameworks", System, true);
350+
AddPath("/Library/Frameworks", System, true);
351+
}
352+
}
353+
return;
354+
}
355+
344356
if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
345357
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
346358
if (HSOpts.UseLibcxx) {

clang/test/Driver/driverkit-path.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ int main() { return 0; }
3131
// INC: [[PATH]]/System/DriverKit/usr/local/include
3232
// INC: /lib{{(64)?}}/clang/{{[^/ ]+}}/include
3333
// INC: [[PATH]]/System/DriverKit/usr/include
34+
// INC: [[PATH]]/System/DriverKit/System/Library/Frameworks (framework directory)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang -cc1 -fcuda-is-device -isysroot /var/empty \
2+
// RUN: -triple nvptx-nvidia-cuda -aux-triple i386-apple-macosx \
3+
// RUN: -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
4+
5+
// RUN: %clang -cc1 -isysroot /var/empty \
6+
// RUN: -triple i386-apple-macosx -aux-triple nvptx-nvidia-cuda \
7+
// RUN: -E -fcuda-is-device -v -o /dev/null -x cuda %s 2>&1 | FileCheck %s
8+
9+
// Check that when we do CUDA host and device compiles on MacOS, we check for
10+
// includes in /System/Library/Frameworks and /Library/Frameworks.
11+
12+
// CHECK-DAG: ignoring nonexistent directory "/var/empty/System/Library/Frameworks"
13+
// CHECK-DAG: ignoring nonexistent directory "/var/empty/Library/Frameworks"

0 commit comments

Comments
 (0)