@@ -253,6 +253,45 @@ OptionalFileEntryRef ModuleMap::findHeader(
253253 return NormalHdrFile;
254254}
255255
256+ // / Determine whether the given file name is the name of a builtin
257+ // / header, supplied by Clang to replace, override, or augment existing system
258+ // / headers.
259+ static bool isBuiltinHeaderName (StringRef FileName) {
260+ return llvm::StringSwitch<bool >(FileName)
261+ .Case (" float.h" , true )
262+ .Case (" iso646.h" , true )
263+ .Case (" limits.h" , true )
264+ .Case (" stdalign.h" , true )
265+ .Case (" stdarg.h" , true )
266+ .Case (" stdatomic.h" , true )
267+ .Case (" stdbool.h" , true )
268+ .Case (" stddef.h" , true )
269+ .Case (" stdint.h" , true )
270+ .Case (" tgmath.h" , true )
271+ .Case (" unwind.h" , true )
272+ .Default (false );
273+ }
274+
275+ // / Determine whether the given module name is the name of a builtin
276+ // / module that is cyclic with a system module on some platforms.
277+ static bool isBuiltInModuleName (StringRef ModuleName) {
278+ return llvm::StringSwitch<bool >(ModuleName)
279+ .Case (" _Builtin_float" , true )
280+ .Case (" _Builtin_inttypes" , true )
281+ .Case (" _Builtin_iso646" , true )
282+ .Case (" _Builtin_limits" , true )
283+ .Case (" _Builtin_stdalign" , true )
284+ .Case (" _Builtin_stdarg" , true )
285+ .Case (" _Builtin_stdatomic" , true )
286+ .Case (" _Builtin_stdbool" , true )
287+ .Case (" _Builtin_stddef" , true )
288+ .Case (" _Builtin_stdint" , true )
289+ .Case (" _Builtin_stdnoreturn" , true )
290+ .Case (" _Builtin_tgmath" , true )
291+ .Case (" _Builtin_unwind" , true )
292+ .Default (false );
293+ }
294+
256295void ModuleMap::resolveHeader (Module *Mod,
257296 const Module::UnresolvedHeaderDirective &Header,
258297 bool &NeedsFramework) {
@@ -297,7 +336,7 @@ bool ModuleMap::resolveAsBuiltinHeader(
297336 llvm::sys::path::is_absolute (Header.FileName ) ||
298337 Mod->isPartOfFramework () || !Mod->IsSystem || Header.IsUmbrella ||
299338 !BuiltinIncludeDir || BuiltinIncludeDir == Mod->Directory ||
300- !isBuiltinHeader (Header.FileName ))
339+ !LangOpts. BuiltinHeadersInSystemModules || ! isBuiltinHeaderName (Header.FileName ))
301340 return false ;
302341
303342 // This is a system module with a top-level header. This header
@@ -373,28 +412,9 @@ static StringRef sanitizeFilenameAsIdentifier(StringRef Name,
373412 return Name;
374413}
375414
376- // / Determine whether the given file name is the name of a builtin
377- // / header, supplied by Clang to replace, override, or augment existing system
378- // / headers.
379- bool ModuleMap::isBuiltinHeader (StringRef FileName) {
380- return llvm::StringSwitch<bool >(FileName)
381- .Case (" float.h" , true )
382- .Case (" iso646.h" , true )
383- .Case (" limits.h" , true )
384- .Case (" stdalign.h" , true )
385- .Case (" stdarg.h" , true )
386- .Case (" stdatomic.h" , true )
387- .Case (" stdbool.h" , true )
388- .Case (" stddef.h" , true )
389- .Case (" stdint.h" , true )
390- .Case (" tgmath.h" , true )
391- .Case (" unwind.h" , true )
392- .Default (false );
393- }
394-
395415bool ModuleMap::isBuiltinHeader (const FileEntry *File) {
396- return File->getDir () == BuiltinIncludeDir &&
397- ModuleMap::isBuiltinHeader (llvm::sys::path::filename (File->getName ()));
416+ return File->getDir () == BuiltinIncludeDir && LangOpts. BuiltinHeadersInSystemModules &&
417+ isBuiltinHeaderName (llvm::sys::path::filename (File->getName ()));
398418}
399419
400420ModuleMap::HeadersMap::iterator
@@ -2484,7 +2504,10 @@ void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken,
24842504 }
24852505
24862506 bool NeedsFramework = false ;
2487- Map.addUnresolvedHeader (ActiveModule, std::move (Header), NeedsFramework);
2507+ // Don't add the top level headers to the builtin modules if the builtin headers
2508+ // belong to the system modules.
2509+ if (!Map.LangOpts .BuiltinHeadersInSystemModules || ActiveModule->isSubModule () || !isBuiltInModuleName (ActiveModule->Name ))
2510+ Map.addUnresolvedHeader (ActiveModule, std::move (Header), NeedsFramework);
24882511
24892512 if (NeedsFramework)
24902513 Diags.Report (CurrModuleDeclLoc, diag::note_mmap_add_framework_keyword)
0 commit comments