This is an archive of the discontinued LLVM Phabricator instance.

[ProfileData] Add option to ignore invalid regions
AbandonedPublic

Authored by modocache on Mar 11 2020, 11:22 AM.

Details

Reviewers
vsk
rnk
arphaman
Summary

Clang's source location information reporting is always improving, but
llvm-cov and LLVM's profiling data reporters are "all-or-nothing": if
just a single region of code coverage data is invalid or malformed, the
entire coverage data file is scrapped, and llvm-cov reports "Failed to
load coverage: Malformed coverage data".

The C++ developers I support rely heavily on coverage data from their
unit tests, and this all-or-nothing approach to reporting has caused that
data to be unreliable. I fixed a recent incident of "Failed to load
coverage" by patching D65428 into an older internal release of Clang
that we use, to fix location information for a single function that had
caused thousands of other functions to not be reported. More recently,
I've discovered that Clang generates invalid coverage data for C++20
coroutines, and this prevents coverage data from being reported for the
entire unit.

Before I can send up a fix for C++20 coroutines, I thought I'd provide a
stop-gap solution: allow developers to invoke
llvm-cov -ignore-malformed-coverage-mapping-regions, which will simply
drop mapping regions with invalid source location information. Using
this option would have allowed the developers I support to get coverage
data for most of their source code, even when Clang could not generate
valid information for specific regions (such as prior to D65428, or prior
to whatever I send up for coroutines).

Diff Detail

Event Timeline

modocache created this revision.Mar 11 2020, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 11:22 AM
modocache edited the summary of this revision. (Show Details)Mar 11 2020, 11:42 AM
vsk added a comment.Mar 16 2020, 3:36 PM

I'm not sure this is the right thing to do. Do you see the 'malformed coverage data' error reported when there isn't a compiler bug? I worry that if this option were made available, frontend support for new language features would lag behind.

Mechanically I think this patch is ok, although I suspect there are more places the coverage reader detects malformed data and subsequently bails out.

I see. No, I think whenever we have malformed coverage data, it points to an underlying bug in the compiler. Still, I think llvm-cov's treatment of invalid data is too severe. Is there a good reason it should bail entirely? If it's able to process all but a single coverage region, it seems like it ought to report what it was able to process, no? I think that at least having the option for llvm-cov to behave this way is helpful, although I can understand if others disagree.

For the time being, I'm working to fix the coverage data flaw in Clang's support of C++20 coroutines. But just to reiterate: it's not just coroutines and new language features that have caused invalid regions to appear in coverage data, there's also been cases such as D65428, which as far as I can tell is a bug in a long-existing language feature. In a sense, it's nice that llvm-cov "fails fast" and reports invalid data, but pragmatically it's also nice to have the capability to make it resilient to frontend bugs. At least, that's what I think -- let me know if you disagree :)

vsk added a comment.Mar 19 2020, 5:41 PM

I see. No, I think whenever we have malformed coverage data, it points to an underlying bug in the compiler. Still, I think llvm-cov's treatment of invalid data is too severe. Is there a good reason it should bail entirely? If it's able to process all but a single coverage region, it seems like it ought to report what it was able to process, no? I think that at least having the option for llvm-cov to behave this way is helpful, although I can understand if others disagree.

For the time being, I'm working to fix the coverage data flaw in Clang's support of C++20 coroutines. But just to reiterate: it's not just coroutines and new language features that have caused invalid regions to appear in coverage data, there's also been cases such as D65428, which as far as I can tell is a bug in a long-existing language feature. In a sense, it's nice that llvm-cov "fails fast" and reports invalid data, but pragmatically it's also nice to have the capability to make it resilient to frontend bugs. At least, that's what I think -- let me know if you disagree :)

I definitely see your point of view. Actually I had a similar perspective when I first started working on this feature. The "fail hard, early" approach created.. quite a bit of up-front work. But the upshot was that we had more confidence in the coverage reports. And we didn't have to add tricky workarounds to hide partially incorrect data (incidentally, re: this patch, if a CounterMappingRegion got messed up, could it be that other CMRs in the function are not quite right?). If compiler bugs which break the coverage workflow are relatively rare (and afaict they now are), istm it's feasible/preferable to fix them early, instead of fleshing out and maintaining a separate alpha-quality coverage reporting mode.

modocache abandoned this revision.Apr 2 2020, 10:22 AM

Yup, makes sense. In the codebase I maintain, I think there are a few distinct coverage issues, so I'll keep this patch applied to my fork of LLVM for the time being, until I send patches to fix those issues. But it sounds like this isn't something that we'd want in LLVM trunk, so I'll close this out. Thanks!