<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/144609>144609</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang Module Cache performs no include path check
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Steelskin
</td>
</tr>
</table>
<pre>
In the attached reproducer case, I have 2 small libraries, called `libv1` and `libv2`. Each of them contain a single header called `header.h` containing a single define `LIB_VALUE`, which expands to either 1 or 2 depending on the library.
There is another library, `includer`, which is made of a single header, `includer.h`. All it does is include `header.h`.
These use module maps defined in `lib.modulemap` and `includer.modulemap` respectively. 2 Overlay files are used to use either the `libv1` or `libv2` library. Finally `main.cc` does nothing but output the content of the `LIB_VALUE` macro it get from `includer.h`.
In the build script, we build `main.cc` with modules enabled, first with `libv1`, then `libv2`, using the same module cache. This results in 2 binaries that both output `1`.
We then build using a new module cache, this time first building `main.cc` with `libv2`, then `libv1`. This results in 2 binaries that both output `2`.
The problem seems to come from the fact that Clang does not perform any path check when loading a module from the cache. This is particularly problematic for Swift on Windows, which relies on module maps to parse the Windows SDK headers. These are versioned in different sub-directories but use the same module map file, resulting in compilation failures when parts of the SDK are already present in the module cache but for another Windows SDK version.
[repro.tar.gz](https://github.com/user-attachments/files/20784554/repro.tar.gz)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVU2P4zYM_TXKhRjDURLP5ODD7EeARbfoYafdY0FLdMyuLBmSnGn66wvaTiaZFgV6CmKK5HuPfBKmxEdPVKvdB7X7tMIxdyHW3zKRSz_Yr5pgz_UXD7kjwJzRdGQh0hCDHQ1FMJhI6Y_wBTo8EWhIPToHjpuIkSlJzKBzZEFVpePmtFZVCeiv_7WqygI-o-kgtNKnBxN8RvaAkNgfHUFHaKdml0Lzh6KTWstp9se3BEste5KTX798-P2356-_flZVKWBeOzYd0J8DepsgByDO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