[clang] [clang] use absolute path for builtin headers during module compilation (PR #68023)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 5 15:23:43 PDT 2023


jansvoboda11 wrote:

> > I was going to suggest keeping Header::PathRelativeToRootModuleDirectory as "float.h", and generating this into the  buffer
> 
> Wouldn't this work without the pragma? Isn't the resource directory always added to the header search paths, so the header should be found correctly if we set PathRelativeToRootModuleDirectory relative to the resource dir for builtin headers?

Yeah, the driver adds `-internal-isystem <resource-dir>/include` to the `-cc1` invocation (on Darwin). From your test-case I assumed you wanted the compilation to succeed even without this include path. If that's not the case then yes, you can simply put `#include "float.h"` into the `<module-includes>` buffer by storing `UnresolvedHeaderDirective::FileName` to `Header::PathRelativeToRootModuleDirectory` and then fixing the module map header resolution by doing this in `ModuleMap::findHeader()`:

```c++
auto Directory = Header.HasBuiltinHeader ? BuiltinIncludeDir : M->Directory;
```

Which effectively mimics what we already do in `ModuleMap::resolveAsBuiltinHeader()`.

https://github.com/llvm/llvm-project/pull/68023


More information about the cfe-commits mailing list