Skip to content

[swift/release/6.2][clang][Darwin] Remove legacy framework search path logic in the frontend #10706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: swift/release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8221,6 +8221,11 @@ def objc_isystem : Separate<["-"], "objc-isystem">,
def objcxx_isystem : Separate<["-"], "objcxx-isystem">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the ObjC++ SYSTEM include search path">;
def internal_iframework : Separate<["-"], "internal-iframework">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the internal system framework search path; these "
"are assumed to not be user-provided and are used to model system "
"and standard frameworks' paths.">;
def internal_isystem : Separate<["-"], "internal-isystem">,
MetaVarName<"<directory>">,
HelpText<"Add directory to the internal system include search path; these "
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ class ToolChain {

/// \name Utilities for implementing subclasses.
///@{
static void addSystemFrameworkInclude(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
const Twine &Path);
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
const Twine &Path);
Expand All @@ -237,6 +240,9 @@ class ToolChain {
addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
const Twine &Path);
static void addSystemFrameworkIncludes(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
ArrayRef<StringRef> Paths);
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
ArrayRef<StringRef> Paths);
Expand Down
17 changes: 9 additions & 8 deletions clang/lib/Driver/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
return true;

// Some include flags shouldn't be skipped if we have a crash VFS
IsInclude = llvm::StringSwitch<bool>(Flag)
.Cases("-include", "-header-include-file", true)
.Cases("-idirafter", "-internal-isystem", "-iwithprefix", true)
.Cases("-internal-externc-isystem", "-iprefix", true)
.Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
.Cases("-isysroot", "-I", "-F", "-resource-dir", true)
.Cases("-iframework", "-include-pch", true)
.Default(false);
IsInclude =
llvm::StringSwitch<bool>(Flag)
.Cases("-include", "-header-include-file", true)
.Cases("-idirafter", "-internal-isystem", "-iwithprefix", true)
.Cases("-internal-externc-isystem", "-iprefix", true)
.Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
.Cases("-isysroot", "-I", "-F", "-resource-dir", true)
.Cases("-internal-iframework", "-iframework", "-include-pch", true)
.Default(false);
if (IsInclude)
return !HaveCrashVFS;
if (StringRef(Flag).starts_with("-index-store-path"))
Expand Down
40 changes: 28 additions & 12 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,17 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
return *cxxStdlibType;
}

/// Utility function to add a system framework directory to CC1 arguments.
void ToolChain::addSystemFrameworkInclude(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
const Twine &Path) {
CC1Args.push_back("-internal-iframework");
CC1Args.push_back(DriverArgs.MakeArgString(Path));
}

/// Utility function to add a system include directory to CC1 arguments.
/*static*/ void ToolChain::addSystemInclude(const ArgList &DriverArgs,
ArgStringList &CC1Args,
const Twine &Path) {
void ToolChain::addSystemInclude(const ArgList &DriverArgs,
ArgStringList &CC1Args, const Twine &Path) {
CC1Args.push_back("-internal-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(Path));
}
Expand All @@ -1194,9 +1201,9 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
/// "C" semantics. These semantics are *ignored* by and large today, but its
/// important to preserve the preprocessor changes resulting from the
/// classification.
/*static*/ void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
ArgStringList &CC1Args,
const Twine &Path) {
void ToolChain::addExternCSystemInclude(const ArgList &DriverArgs,
ArgStringList &CC1Args,
const Twine &Path) {
CC1Args.push_back("-internal-externc-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(Path));
}
Expand All @@ -1208,19 +1215,28 @@ void ToolChain::addExternCSystemIncludeIfExists(const ArgList &DriverArgs,
addExternCSystemInclude(DriverArgs, CC1Args, Path);
}

/// Utility function to add a list of system framework directories to CC1.
void ToolChain::addSystemFrameworkIncludes(const ArgList &DriverArgs,
ArgStringList &CC1Args,
ArrayRef<StringRef> Paths) {
for (const auto &Path : Paths) {
CC1Args.push_back("-internal-iframework");
CC1Args.push_back(DriverArgs.MakeArgString(Path));
}
}

/// Utility function to add a list of system include directories to CC1.
/*static*/ void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
ArgStringList &CC1Args,
ArrayRef<StringRef> Paths) {
void ToolChain::addSystemIncludes(const ArgList &DriverArgs,
ArgStringList &CC1Args,
ArrayRef<StringRef> Paths) {
for (const auto &Path : Paths) {
CC1Args.push_back("-internal-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(Path));
}
}

/*static*/ std::string ToolChain::concat(StringRef Path, const Twine &A,
const Twine &B, const Twine &C,
const Twine &D) {
std::string ToolChain::concat(StringRef Path, const Twine &A, const Twine &B,
const Twine &C, const Twine &D) {
SmallString<128> Result(Path);
llvm::sys::path::append(Result, llvm::sys::path::Style::posix, A, B, C, D);
return std::string(Result);
Expand Down
20 changes: 20 additions & 0 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,26 @@ void AppleMachO::AddClangSystemIncludeArgs(
}
}

void DarwinClang::AddClangSystemIncludeArgs(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
AppleMachO::AddClangSystemIncludeArgs(DriverArgs, CC1Args);

if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc))
return;

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

// Add <sysroot>/System/Library/Frameworks
// Add <sysroot>/System/Library/SubFrameworks
// Add <sysroot>/Library/Frameworks
SmallString<128> P1(Sysroot), P2(Sysroot), P3(Sysroot);
llvm::sys::path::append(P1, "System", "Library", "Frameworks");
llvm::sys::path::append(P2, "System", "Library", "SubFrameworks");
llvm::sys::path::append(P3, "Library", "Frameworks");
addSystemFrameworkIncludes(DriverArgs, CC1Args, {P1, P2, P3});
}

bool DarwinClang::AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args,
llvm::SmallString<128> Base,
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/Darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
/// @name Apple ToolChain Implementation
/// {

void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;

RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;

void AddLinkRuntimeLibArgs(const llvm::opt::ArgList &Args,
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,8 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
: OPT_internal_externc_isystem;
GenerateArg(Consumer, Opt, It->Path);
}
for (; It < End && Matches(*It, {frontend::System}, true, true); ++It)
GenerateArg(Consumer, OPT_internal_iframework, It->Path);

assert(It == End && "Unhandled HeaderSearchOption::Entry.");

Expand Down Expand Up @@ -3637,6 +3639,8 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
Group = frontend::ExternCSystem;
Opts.AddPath(A->getValue(), Group, false, true);
}
for (const auto *A : Args.filtered(OPT_internal_iframework))
Opts.AddPath(A->getValue(), frontend::System, true, true);

// Add the path prefixes which are implicitly treated as being system headers.
for (const auto *A :
Expand Down
19 changes: 3 additions & 16 deletions clang/lib/Lex/InitHeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
break;
}

if (triple.isOSDarwin())
return false;

return true; // Everything else uses AddDefaultIncludePaths().
}

Expand All @@ -337,22 +340,6 @@ 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("/System/Library/SubFrameworks", System, true);
AddPath("/Library/Frameworks", System, true);
}
}
return;
}

if (Lang.CPlusPlus && !Lang.AsmPreprocessor &&
HSOpts.UseStandardCXXIncludes && HSOpts.UseStandardSystemIncludes) {
if (HSOpts.UseLibcxx) {
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CAS/depscan-prefix-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// RUN: -isysroot %S/Inputs/SDK \
// RUN: -resource-dir %S/Inputs/toolchain_dir/usr/lib/clang/1000 \
// RUN: -internal-isystem %S/Inputs/toolchain_dir/usr/lib/clang/1000/include \
// RUN: -internal-iframework %S/Inputs/SDK/Library/Frameworks \
// RUN: -working-directory %t.d \
// RUN: -fcas-path %t.d/cas \
// RUN: -fdepscan-prefix-map=%S=/^source \
Expand All @@ -23,6 +24,7 @@
// RUN: -isysroot %S/Inputs/SDK \
// RUN: -resource-dir %S/Inputs/toolchain_dir/lib/clang/1000 \
// RUN: -internal-isystem %S/Inputs/toolchain_dir/lib/clang/1000/include \
// RUN: -internal-iframework %S/Inputs/SDK/Library/Frameworks \
// RUN: -working-directory %t.d \
// RUN: -fcas-path %t.d/cas \
// RUN: -fdepscan-prefix-map=%S=/^source \
Expand All @@ -40,6 +42,7 @@
// RUN: -isysroot %S/Inputs/SDK \
// RUN: -resource-dir %S/Inputs/toolchain_dir/usr/lib/clang/1000 \
// RUN: -internal-isystem %S/Inputs/toolchain_dir/usr/lib/clang/1000/include \
// RUN: -internal-iframework %S/Inputs/SDK/Library/Frameworks \
// RUN: -working-directory %t.d \
// RUN: -fcas-path %t.d/cas \
// RUN: -fdepscan-prefix-map=%S=/^source \
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions clang/test/Driver/darwin-framework-search-paths.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// UNSUPPORTED: system-windows
// Windows is unsupported because we use the Unix path separator `/` in the test.

// RUN: %clang %s -target arm64-apple-macosx15.1 -isysroot %S/Inputs/MacOSX15.1.sdk -c %s -### 2>&1 \
// RUN: | FileCheck -DSDKROOT=%S/Inputs/MacOSX15.1.sdk %s
//
// CHECK: "-cc1"
// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
// CHECK-SAME: "-internal-iframework" "[[SDKROOT]]/System/Library/Frameworks"
// CHECK-SAME: "-internal-iframework" "[[SDKROOT]]/System/Library/SubFrameworks"
// CHECK-SAME: "-internal-iframework" "[[SDKROOT]]/Library/Frameworks"

// Verify that -nostdlibinc and -nostdinc removes the default search paths.
//
// RUN: %clang %s -target arm64-apple-macosx15.1 -isysroot %S/Inputs/MacOSX15.1.sdk -nostdinc -c %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-NOSTD -DSDKROOT=%S/Inputs/MacOSX15.1.sdk %s
//
// RUN: %clang %s -target arm64-apple-macosx15.1 -isysroot %S/Inputs/MacOSX15.1.sdk -nostdlibinc -c %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-NOSTD -DSDKROOT=%S/Inputs/MacOSX15.1.sdk %s
//
// CHECK-NOSTD: "-cc1"
// CHECK-NOSTD: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
// CHECK-NOSTD-NOT: "-internal-iframework"
18 changes: 0 additions & 18 deletions clang/test/Driver/darwin-subframeworks.c

This file was deleted.

16 changes: 9 additions & 7 deletions clang/test/Driver/driverkit-path.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ int main() { return 0; }
// LD64-NEW: "-isysroot" "[[PATH:[^"]*]]Inputs/DriverKit19.0.sdk"
// LD64-NEW-NOT: "-L[[PATH]]Inputs/DriverKit19.0.sdk/System/DriverKit/usr/lib"
// LD64-NEW-NOT: "-F[[PATH]]Inputs/DriverKit19.0.sdk/System/DriverKit/System/Library/Frameworks"
// LD64-NEW-NOT: "-F[[PATH]]Inputs/DriverKit19.0.sdk/System/DriverKit/System/Library/SubFrameworks"


// RUN: %clang %s -target x86_64-apple-driverkit19.0 -isysroot %S/Inputs/DriverKit19.0.sdk -E -v -x c++ 2>&1 | FileCheck %s --check-prefix=INC
// RUN: %clang %s -target x86_64-apple-driverkit19.0 -isysroot %S/Inputs/DriverKit19.0.sdk -x c++ -### 2>&1 \
// RUN: | FileCheck %s -DSDKROOT=%S/Inputs/DriverKit19.0.sdk --check-prefix=INC
//
// INC: -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]]
// INC-LABEL: #include <...> search starts here:
// 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)
// INC: "-isysroot" "[[SDKROOT]]"
// INC: "-internal-isystem" "[[SDKROOT]]/System/DriverKit/usr/local/include"
// INC: "-internal-isystem" "{{.+}}/lib{{(64)?}}/clang/{{[^/ ]+}}/include"
// INC: "-internal-externc-isystem" "[[SDKROOT]]/System/DriverKit/usr/include"
// INC: "-internal-iframework" "[[SDKROOT]]/System/DriverKit/System/Library/Frameworks"
// INC: "-internal-iframework" "[[SDKROOT]]/System/DriverKit/System/Library/SubFrameworks"
13 changes: 0 additions & 13 deletions clang/test/Preprocessor/cuda-macos-includes.cu

This file was deleted.

1 change: 1 addition & 0 deletions clang/unittests/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_clang_unittest(FrontendTests
PCHPreambleTest.cpp
ReparseWorkingDirTest.cpp
OutputStreamTest.cpp
SearchPathTest.cpp
TextDiagnosticTest.cpp
UtilsTest.cpp
)
Expand Down
Loading