This is an archive of the discontinued LLVM Phabricator instance.

[Coverage] Propogate counter to condition of conditional operator
ClosedPublic

Authored by zequanwu on Feb 2 2021, 8:54 PM.

Details

Summary

Clang usually propagates counter mapping region for conditions of if, while,
for, etc from parent counter. We should do the same for condition of conditional operator.

Diff Detail

Event Timeline

zequanwu requested review of this revision.Feb 2 2021, 8:54 PM
zequanwu created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2021, 8:54 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
pirama added a subscriber: pirama.Feb 2 2021, 10:33 PM
vsk accepted this revision.Feb 3 2021, 8:41 AM

Thanks, lgtm.

This revision is now accepted and ready to land.Feb 3 2021, 8:41 AM
rnk added a comment.Feb 3 2021, 10:45 AM

Nice. I believe there are some integration tests in compiler-rt/test/profile. First, please run them and make sure they pass. Second, @vsk, do you think it's worth adding an integration test for this, seeing as the bug is really only observable when you put all the coverage tools together?

I tested it locally. They are all passed.

This revision was landed with ongoing or failed builds.Feb 3 2021, 1:33 PM
This revision was automatically updated to reflect the committed changes.
vsk added a comment.Feb 3 2021, 2:06 PM

How was the issue spotted? If there was a crash or an incorrect coverage bug that's not triggered by one of the existing frontend tests, it'd be worth adding a regression test. If the problem can't be replicated without involving llvm-cov, this can be an integration test.

In D95918#2540367, @vsk wrote:

How was the issue spotted? If there was a crash or an incorrect coverage bug that's not triggered by one of the existing frontend tests, it'd be worth adding a regression test. If the problem can't be replicated without involving llvm-cov, this can be an integration test.

The issue was spotted by @pirama. But this doesn't completely solve the problem. When I was investigating the issue, I noticed condition expression of conditional operator was not given a counter. So, I sent this patch.

For the issue reported by @pirama, it is that llvm-cov shows following:

1|       |#include <stdlib.h>
2|       |
3|      1|int main() {
4|      1|  return getenv(
5|      0|      "TEST") ? 1
6|      1|              : 0;
7|      1|}

Here are the debug dump.

Combined regions:
  3:12 -> 7:2 (count=1)
  4:10 -> 5:14 (count=1)
  5:15 -> 5:17 (count=0)
  5:17 -> 5:18 (count=0)
  6:17 -> 6:18 (count=1)
Segment at 3:12 (count = 1), RegionEntry
Segment at 4:10 (count = 1), RegionEntry
Segment at 5:14 (count = 1)
Segment at 5:15 (count = 0), Gap
Segment at 5:17 (count = 0), RegionEntry
Segment at 5:18 (count = 1)
Segment at 6:17 (count = 1), RegionEntry
Segment at 6:18 (count = 1)
Segment at 7:2 (count = 0), Skipped

I am working on this.