[PATCH] D159064: [Modules] Make clang modules for the C standard library headers

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 08:10:05 PDT 2023


dexonsmith added inline comments.


================
Comment at: clang/lib/Headers/__stddef_null.h:14
+ * __need_NULL and rely on stddef.h to redefine NULL to the correct value again.
+ * Modules don't support redefining macros like that, but support that pattern
+ * in the non-modules case.
----------------
iana wrote:
> I couldn't come up with anything clever to support this in modules. If I get rid of the guard, `NULL` still doesn't get redefined in modules. If I move the `undef` to stddef.h then `NULL` gets undefined, but not redefined. So I think precompiled modules must inherently have `#pragma once` semantics. If we really had to, we could move this back into stddef.h and let it be textual, but it's distasteful that `NULL` gets defined in every single module that includes stddef.h and has to be merged later.
Modules are, in a way, stronger than `#pragma once`. Each module is a separate translation unit. If there's a module around `__stddef_null.h`, then it will only be compiled once, and any definitions imported from there. Other importing TUs get those definitions per the context the module was compiled in (they don't re-compile the code in their own context...).

It seems like a regression for `NULL` to degrade from `((void *)0)` to `0` since it loses type safety, which is rather rare and precious in C code. Maybe this header should remain textual when deployed to platforms that rely on this dance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159064/new/

https://reviews.llvm.org/D159064



More information about the cfe-commits mailing list