Created attachment 17951 [details] full reproducer. Currently including "stddef.h" or other builtin headers when modules is enabled causes Clang to find `module.modulemap` files along the wrong search paths. For example, given the following configuration: 1) A project "my_project" which provides a module map for its headers. 2) The system has an installation of "my_project" in "/usr/local/include/my_project". 3) A user has a local development copy of "my_project" that they are trying to compile. While compiling the local copy both the in-tree and system installed module.modulemap are along the header include paths, however the local copy has precedence and that's the module.modulemap Clang initially selects. However after Clang processes a `#include "stddef.h"` it will end up processing `/usr/local/include/my_project/module.modulemap`. This causes module re-definition compile errors. This bug is currently preventing LLVM from installing it's module maps, because this bug will be hit when re-compiling LLVM.
This may be due to the special case logic in ModuleMap::findKnownHeader w.r.t. builtin includes?
@Sean Almost certainly. I believe the re-definition error is emitted when trying to find a module map for the module _Builtin_stddef_max_align_t. Is anybody interested in working on this? I've tried with no luck (because I don't know enough about clang). I would love to start installing the LLVM modulemaps soon :-)
Created attachment 18067 [details] drop-in clang test case. I've attached a test-case written for Clang's test suite. So anybody who wants to try and fix this doesn't need to write the test themselves.
Eric, given your description it seems that this would also happen with other system headers as well; as long as some project has a header with the same name. Did you happen to verify that too?
No it seems to be specific to stddef and likely _Builtin_stddef_max_align_t (Which is given special behavion in Module::directlyUses). It doesn't reproduce with stdint.h, stdarg.h, float.h. (And many other examples enumerated under ModuleMap::isBuiltinHeader).
Created attachment 18281 [details] drop-in clang test case v2 Add an improved drop in clang test case.
As others have pointed out, this has nothing to do with `stddef.h` specifically. It's a general problem.
Created attachment 21025 [details] reproducer without stddef.h Here is a new reproducer that doesn't depend on any system headers.