Skip to content

[ClangImporter] -Xclang -fbuiltin-headers-in-system-modules is being passed when it shouldn't #73814

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

Merged
merged 1 commit into from
May 22, 2024
Merged
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
10 changes: 2 additions & 8 deletions lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,11 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) {
return clangDriverArgs;
}

static bool shouldInjectLibcModulemap(const llvm::Triple &triple) {
return triple.isOSGlibc() || triple.isOSOpenBSD() || triple.isOSFreeBSD() ||
triple.isAndroid() || triple.isMusl() || triple.isOSWASI();
}

static SmallVector<std::pair<std::string, std::string>, 2>
getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName,
std::optional<StringRef> maybeHeaderFileName,
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &vfs) {
const llvm::Triple &triple = ctx.LangOpts.Target;
if (!shouldInjectLibcModulemap(triple))
return {};

// Extract the libc path from Clang driver.
auto clangDriver = createClangDriver(ctx, vfs);
Expand Down Expand Up @@ -559,7 +552,8 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
} else if (triple.isMusl()) {
libcFileMapping =
getLibcFileMapping(ctx, "musl.modulemap", StringRef("SwiftMusl.h"), vfs);
} else {
} else if (triple.isOSGlibc() || triple.isOSOpenBSD() ||
triple.isOSFreeBSD() || triple.isAndroid()) {
// Android/BSD/Linux Mappings
libcFileMapping = getLibcFileMapping(ctx, "glibc.modulemap",
StringRef("SwiftGlibc.h"), vfs);
Expand Down