From a1f406fd400766685b780c7b768f9550791cb6a5 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Wed, 22 May 2024 09:12:54 +0100 Subject: [PATCH] [ClangImporter] `-Xclang -fbuiltin-headers-in-system-modules` is being passed when it shouldn't We were accidentally setting `requiresBuiltinHeadersInSystemModules` because the `else` here gets executed for things that are not WASI or Musl. Fix by making it conditional. rdar://128219177 --- lib/ClangImporter/ClangIncludePaths.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index 11d95131b701b..f5183091bde37 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -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, 2> getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName, std::optional maybeHeaderFileName, const llvm::IntrusiveRefCntPtr &vfs) { const llvm::Triple &triple = ctx.LangOpts.Target; - if (!shouldInjectLibcModulemap(triple)) - return {}; // Extract the libc path from Clang driver. auto clangDriver = createClangDriver(ctx, vfs); @@ -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);