[PATCH] D159483: [Modules] Add a flag to control builtin headers being in system modules

Ian Anderson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 11:54:23 PDT 2023


iana created this revision.
iana added reviewers: aaron.ballman, rsmith, efriedma, ldionne, ChuanqiXu, Bigcheese, vsapsai, benlangmuir.
Herald added a subscriber: ributzka.
Herald added a project: All.
iana requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Including select builtin headers in system modules is a workaround for module cycles, primarily in Apple's Darwin module that includes all of its C standard library headers. The workaround is problematic because it doesn't include all of the builtin headers (inttypes.h is notably absent), and it also doesn't include C++ headers. The straightforward for for this is to make top level modules for all of the C standard library headers and unwind.h in C++, clang, and the OS.

However, doing so in clang before the OS modules are ready re-introduces the module cycles. Add a -fbuiltin-headers-in-system-modules option to control if the special builtin headers belong to system modules or builtin modules. Pass the option by default for Apple.

The __stdarg and __stddef headers need to use header guards when they're precompiled into their builtin modules, but need to be repeatedly included when they're used in system modules. Add a builtin_headers_in_system_modules feature so those headers can conditionally ignore their header guards. Always define the header guards for consistency. stdarg.h and stddef.h will be textual headers in the builtin modules, and so need to be repeatedly included in both the system and builtin module case. Ignore their header guards when building with modules, but still define the guards.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159483

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_max_align_t.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/lib/Lex/ModuleMap.cpp
  clang/test/Modules/Werror-Wsystem-headers.m
  clang/test/Modules/context-hash.c
  clang/test/Modules/crash-vfs-include-pch.m
  clang/test/Modules/cstd.m
  clang/test/Modules/pch-used.m
  clang/test/Modules/shadowed-submodule.m
  clang/test/Modules/stddef.c
  clang/test/Modules/stddef.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159483.556191.patch
Type: text/x-patch
Size: 35038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230907/3cc835d7/attachment-0001.bin>


More information about the cfe-commits mailing list