<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119952>119952</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm-cov: Branches cannot be seen on macro definitions in source view
</td>
</tr>
<tr>
<th>Labels</th>
<td>
tools:llvm-cov
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chapuni
</td>
</tr>
</table>
<pre>
If a macro definition has branches (`&&` `||` `?:`), they cannot be seen in source view.
They can be seen in expanded subviews if expansion is enabled.
They causes hidden counts between the summary and the source view. (See also #119282)
This has been there since the introduction of branch coverage.
https://reviews.llvm.org/D84467
https://github.com/llvm/llvm-project/commit/9f2967bcfe2f7d1fc02281f0098306c90c2c10a5#diff-44b7cba1a9d87f9ec9e067d93ea9d29ea4d9c669942d73f89233e39e28f9a5f0R680-R683
in `CoverageMapping::getCoverageForFile(StringRef Filename)`:
```C++
// Capture branch regions specific to the function (excluding expansions).
for (const auto &CR : Function.CountedBranchRegions)
if (FileIDs.test(CR.FileID) && (CR.FileID == CR.ExpandedFileID))
FileCoverage.BranchRegions.push_back(CR);
```
I don't understand the intent. `CountedBranchRegions` doesn't have any `Expansion`s. `CR.ExpandedFileID` will be always zero.
As the result, it is handled as if `CR.FileID == 0`. This prevents branches to be seen outside the function.
(Expansion subview can show them since it uses `getCoverageForFunction()`)
I think it'd make sense to show branches on macro defs in the source view, to prune 2nd condition `(CR.FileID == CR.ExpandedFileID)`.
What do you think, @evodius96 ?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVU2P4ygQ_TXkUhoLg2Obgw_p9ETqw16yI-1xhaEcs-1AZCA92V-_Ajvpj9nDbgupAyq_qnq8ekjvzckidmT7RLbPGxnD6OZOjfISrdn0Tt-6lwEknKWaHWgcjDXBOAuj9NDP0qoRPRDWkpoSVqdVU0ibZp_WuuEHwnc5RBC2hzDiDZS01gXoETyiBWPBuzgrhK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