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

    <tr>
        <th>Summary</th>
        <td>
            `/showIncludes` implicit dependency scanning sporadically broken with clang-cl (and Ninja) due to mixed output
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Cross posted this issue with Ninja in ninja-build/ninja#2138.

>From what I can tell clang-cl (14.0) currently outputs regular diagnostics to `stderr` and `/showIncludes` based `Note: including file:` notes to `stdout` (`cl` on the other hand outputs both to `stdout` which is why there this issue does not exist).

This is somewhat hard to reproduce and seems to depend on independent buffering and flushing of the two streams and the fact that Ninja currently merges both streams into one before parsing `/showIncludes` based notes for preprocessor included files.

When the mixing of the two streams happens at inopportune times this for me results in `/showIncludes` notes leaking to the console (meaning they at that point do not contribute to the list of implicit header dependencies either) or generation of non-existing header paths (where part of the path is actually a diagnostic that ended up at the end of the note) which I've only indirectly noticed due to ninja generated `path too long` errors.

The issue seems to get further exacerbated by e.g. ANSI colored diagnostic (-fansi-escape-codes), CMake / CTest launchers and sccache (which capture and forward stderr/stdout) presumably because there may further influence when and how the two output streams are mixed.

A fix presumably would involve parsing `/showIncludes` notes only from the unmerged streams independently (or just `stderr`) or clang-cl outputting both diagnostics and `/showIncludes` notes to `stdout` (like `cl`does).

Not sure which is easier or more realistic.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVU1v6zYQ_DXyhbBhy3ZiH3xI8xAgh-bSB_RMkSuJCUUK_Ijj_vrOUrbjvDYtYMik-LGzszOrxuvT4TH4GMXoYyItUm-iMDFmEkeTevFi3KsUxgnHg3mTjdVV_VRmVb2uV-vdolr-qJYP0_Mp-EEce5nEs1DSiUTWCmWl6-bKiqrerTaLZVXvhc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