[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 12:46:10 PDT 2023


jansvoboda11 wrote:

> If the resource dir is outside of the cwd then you would have to have an absolute path here anyway, wouldn't you?

Yes. But my understanding was that's not what you're interested in. I thought you're trying to fix the situation where your resource dir is in the CWD, so that's the context I'm assuming. Is that correct?

>> This is now always storing an absolute path into Header::PathRelativeToRootModuleDirectory for built-in headers

> Wouldn't this always have been the case? I'll check shortly with a resource dir picked up via toolchain bundle layout.

I was considering your test case, where we'd previously store `"resource-dir/include/float.h"` into `Header::PathRelativeToRootModuleDirectory` (knowing that ends up causing failures down the line). Now we're essentially guaranteeing that for built-in headers, the path is absolute (`"/path/to/cwd/resource-dir/include/float.h"`), contrary to what the member name suggests. I find that a bit confusing.

> This is the use case I am trying to support, via -fmodule-file-home-is-cwd ...

But `-fmodule-file-home-is-cwd` will not go as far as fixing up the contents of `SourceManager` buffers. So while all the paths you serialize into the PCM will get "relativized", the `<module-includes>` buffer would still contain the absolute path in the form of:

```
#include "/path/to/cwd/resource-dir/include/float.h"
```

If you originally compiled the PCM on machine A that has CWD set to `"/path/to/cwd"`, you could probably still successfully load it on machine B with CWD set to `"/blah"`. But if you re-compiled the PCM on machine B, the output would not be the same, since the PCM would now embed this into the `<module-includes>` buffer instead:

```
#include "/blah/resource-dir/include/float.h"
```

Is that not a concern for your use-case?

>> Maybe prepending #pragma before #include of each builtin header?

> Could you expand on this? Not sure I get the idea.

I was going to suggest keeping `Header::PathRelativeToRootModuleDirectory` as `"float.h"`, and generating this into the `<module-includes>` buffer:

```
#pragma prefix the following header path with the builtin includes directory
#include "float.h"
```

This would ensure both machines A and B produce identical PCM files.

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


More information about the cfe-commits mailing list