[PATCH] D25040: [Coverage] Do not emit coverage mappings for functions marked 'unused'

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 15:56:44 PDT 2016

vsk added a comment.

In https://reviews.llvm.org/D25040#556109, @arphaman wrote:

> Thanks for working on this, I have a couple of comments/questions:
> - The current logic doesn't work correctly for a test case that's shown below:
>   ``` class C2 { void __attribute__((unused)) m4() { } void __attribute__((unused)) m5(); }; ``` The method 'm4' actually gets covered with a zero region. I suspect you might have to perform the check for the attribute in the 'EmptyCoverageMappingBuilder' class as well.

Thanks, I'll take a look at that.

> - I understand the value in ignoring coverage for unused functions which aren't actually used anywhere. But people can still use them freely, so do you think that it would be a good idea to provide coverage for those functions when they are actually used?

Yeah. Things like readCpuInfo() (lib/Support/Host.cpp) are marked 'unused', but we shouldn't suppress coverage for them.

Based on a quick skim [1], it seems like most functions marked 'unused' aren't called normally. Maybe that's all the more reason to provide coverage for them: if they *are* executed, it would be helpful to know. But the common case seems to be 'dump' or 'verify' methods that are called from lldb/gtest, and I don't think it's useful to have coverage for these.

I'm not sure how we'd determine that the function is actually used. Do you have an approach in mind? IIRC libclang has an API which allows you to count the users of a USR, but this isn't helpful without a view of all translation units.

[1] $ grep -rnE -A10 "LLVM_ATTRIBUTE_UNUSED( |$)" lib/


More information about the cfe-commits mailing list