This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][modules] Fix <stddef.h>'s module definition
Needs ReviewPublic

Authored by EricWF on Dec 5 2016, 5:40 PM.

Details

Summary

Currently libc++'s stddef.h is treated as a textual header by the module map, and technically this is correct because the header is non-modular (at least during normal compilation).
Unfortunatly this means that the stddef module doesn't own any of the definitions it should, like size_t and ptrdiff_t. which end up getting owned by random STL headers.

Fortunately I believe that libc++'s stddef.h *is* modular due to Clang internals which handle modules containing stddef.h differently. Specifically Clang translates the module definition module stddef_h { header "stddef.h" export *} into

module stddef_h {
  textual header "clang/builtin-includes/.../stddef.h"
  header "libcxx/include/stddef.h"
}

This means that the __need_* macros will always be resolved and #undef-ed by Clang's stddef.h header before processing libc++'s. Therefore we should be able to treat libc++'s header as non-textual. This allows libc++ to actually build a stddef_h module containing the correct definitions.

I've tested this change both with and without local sub-module visibility and on both Linux and OS X.

@rsmith What do you think? Does the above rational make sense?

Diff Detail

Event Timeline

EricWF updated this revision to Diff 80350.Dec 5 2016, 5:40 PM
EricWF retitled this revision from to [libcxx][modules] Fix <stddef.h>'s module definition.
EricWF updated this object.
EricWF added reviewers: rsmith, manmanren, bruno.
EricWF added subscribers: cfe-commits, rsmith.
bruno resigned from this revision.Nov 9 2020, 11:55 AM