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

    <tr>
        <th>Summary</th>
        <td>
            'llvm-cov export' does not respect SOURCES filter if there are no executable lines in SOURCES files.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Repro steps:
1. Create a framework with source files but no executable lines (all protocols), which imports another framework that does have executable lines. (Note that we use Buck, so this is a Buck module that contains only protocols, and that has a dep on another module that has executable code)
2. Run llvm-cov export on that binary with SOURCES filter to be only the source files in that framework (so protocols only)

Expect: coverage report to either contain nothing (because all files are either filtered out or have no executable lines) or contain files in SOURCES filter with no lines
Actual: coverage report contains line data and coverage totals for all files in imported frameworks.

This bug report is related to https://reviews.llvm.org/D89359 because that diff fixes a different variant of this bug (where the --ignore-filename-regex flag filters out all source files) but not this specific bug (where the source files that are within the SOURCES filter have no executable lines).

 I believe this is due to where we apply the fix of grabbing whether the SourceFiles array was initially empty. In the diff, this value is saved in addCollectedPath which is called from collectPaths, which may be too late because files without executable lines in SourceFiles at that point had already been removed. 

>From reading the code, I think files without executable lines get removed in the load method, so caching the SourceFiles array empty flag needs to happen in the load method, before removeUnmappedInputs (where files not in the "coverage mapping" are removed).

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVcFy4jgQ_RpzUUEZEyAcfMiQYSqX2a3MzmGPbakN2siWS5Ih_P12S8ZAktqtokIsWt2v33vdrqw6l6_YOSt8wM5ni6csf87yp_lMbB1CQAGidtDgybo3cdLhILztnURRa4NeVH0QrRX4jrIPUBkURrd0nhWPYIygxMFKa3xWbLJiK04HLQ9CN511wQtobTiguykQDhCEspTgAEf8lHbGeX9aQhUDTyh6j-JbL984ubd0rL2gD8RD0VjVmyF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