Skip to content

Commit 61999b1

Browse files
authored
[clang][Darwin] Remove legacy framework search path logic in the frontend (#75841)
This removes a long standing piece of technical debt. Most other platforms have moved all their header search path logic to the driver, but Darwin still had some logic for setting framework search paths present in the frontend. This patch moves that logic to the driver alongside existing logic that already handles part of these search paths. This is intended to be a pure refactor without any functional change visible to users, since the search paths before and after should be the same, and in the same order. The change in the tests is necessary because we would previously add the DriverKit framework search path in the frontend regardless of whether we actually need to, which we now handle correctly because the driver checks for ld64-605.1+. Fixes #75638
1 parent 568db84 commit 61999b1

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

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

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
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
764769
{
765770
bool NonStandardSearchPath = false;
766771
const auto &Triple = getToolChain().getTriple();
@@ -771,18 +776,22 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
771776
(Version.getMajor() == 605 && Version.getMinor().value_or(0) < 1);
772777
}
773778

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-
};
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) {
784790
AddSearchPath("-L", "/usr/lib");
785791
AddSearchPath("-F", "/System/Library/Frameworks");
792+
} else if (!Triple.isDriverKit()) {
793+
AddSearchPath("-F", "/System/Library/Frameworks");
794+
AddSearchPath("-F", "/Library/Frameworks");
786795
}
787796
}
788797
}

clang/lib/Lex/InitHeaderSearch.cpp

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

327+
if (triple.isOSDarwin())
328+
return false;
329+
327330
return true; // Everything else uses AddDefaultIncludePaths().
328331
}
329332

@@ -338,21 +341,6 @@ void InitHeaderSearch::AddDefaultIncludePaths(
338341
if (!ShouldAddDefaultIncludePaths(triple))
339342
return;
340343

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-
356344
if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
357345
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
358346
if (HSOpts.UseLibcxx) {

clang/test/Driver/driverkit-path.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ 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)

clang/test/Preprocessor/cuda-macos-includes.cu

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)