<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61006>61006</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-scan-deps unable to find system headers in p1689 format
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:modules
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            ChuanqiXu9
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mordante
      </td>
    </tr>
</table>

<pre>
    While testing modules with CMake I ran into an issue that some system headers are not found.

I tested with `Debian clang version 17.0.0 (++20230226071743+b8df886c1e2a-1~exp1~20230226071846.576)`

And this code
```
module;
#include <vector>
export module test;
void test() {}
```
Compilation with clang succeeds
`/usr/bin/clang++-17 -stdlib=libc++ -std=c++20 -x c++ test.cppm -c -o /tmp/test.cppm.o`

But testing with the dependency scanner
`/usr/bin/clang-scan-deps-17 -format=p1689 -- /usr/bin/clang++-17 -stdlib=libc++ -std=c++20 -x c++ test.cppm -c -o /tmp/test.cppm.o`

Fails with the following output
```
Error while scanning dependencies for test.cppm:
In file included from test.cppm:3:
In file included from /usr/bin/../include/c++/v1/vector:281:
In file included from /usr/bin/../include/c++/v1/__algorithm/copy.h:12:
In file included from /usr/bin/../include/c++/v1/__algorithm/copy_move_common.h:12:
In file included from /usr/bin/../include/c++/v1/__algorithm/iterator_operations.h:15:
In file included from /usr/bin/../include/c++/v1/__iterator/advance.h:26:
In file included from /usr/bin/../include/c++/v1/cstdlib:87:
In file included from /usr/bin/../include/c++/v1/stdlib.h:94:
In file included from /usr/include/stdlib.h:31:
/usr/bin/../include/c++/v1/stddef.h:17:15: fatal error: 'stddef.h' file not found
{
  "revision": 0,
  "rules": [],
  "version": 1
}
```
The line where the header is not found uses `#include_next <stddef.h>` to include `stddef.h`.

I get similar errors when I don't specify libc++ and use libstdc++.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVs2O6yg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