r276716 - [Coverage] Do not write out coverage mappings with zero entries

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 26 13:39:58 PDT 2016


Vedant Kumar via cfe-commits <cfe-commits at lists.llvm.org> writes:
> Hi Justin,
>
> Could you take a look at this code coverage fix?
>
> It skips visiting decls if they would require context from system headers to
> present properly. This prevents us from writing out an empty coverage mapping
> for the lambda in `assert([] { return true; }());`.
>
> I think it would be a good idea to get it into the 3.9 release.

Yep, I think this should go into 3.9 as well. LGTM.

> thanks,
> vedant
>
>> On Jul 25, 2016, at 5:24 PM, Vedant Kumar via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>> 
>> Author: vedantk
>> Date: Mon Jul 25 19:24:59 2016
>> New Revision: 276716
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=276716&view=rev
>> Log:
>> [Coverage] Do not write out coverage mappings with zero entries
>> 
>> After r275121, we stopped mapping regions from system headers. Lambdas
>> declared in regions belonging to system headers started producing empty
>> coverage mappings, since the files corresponding to their spelling locs
>> were being ignored.
>> 
>> The coverage reader doesn't know what to do with these empty mappings.
>> This commit makes sure that we don't produce them and adds a test. I'll
>> make the reader stricter in a follow-up commit.
>> 
>> Added:
>>    cfe/trunk/test/CoverageMapping/system_macro.cpp
>>      - copied, changed from r276711, cfe/trunk/test/CoverageMapping/system_macro.c
>> Removed:
>>    cfe/trunk/test/CoverageMapping/system_macro.c
>> Modified:
>>    cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
>> 
>> Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=276716&r1=276715&r2=276716&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Jul 25 19:24:59 2016
>> @@ -352,6 +352,9 @@ struct EmptyCoverageMappingBuilder : pub
>>     gatherFileIDs(FileIDMapping);
>>     emitSourceRegions();
>> 
>> +    if (MappingRegions.empty())
>> +      return;
>> +
>>     CoverageMappingWriter Writer(FileIDMapping, None, MappingRegions);
>>     Writer.write(OS);
>>   }
>> @@ -605,6 +608,9 @@ struct CounterCoverageMappingBuilder
>>     emitExpansionRegions();
>>     gatherSkippedRegions();
>> 
>> +    if (MappingRegions.empty())
>> +      return;
>> +
>>     CoverageMappingWriter Writer(VirtualFileMapping, Builder.getExpressions(),
>>                                  MappingRegions);
>>     Writer.write(OS);
>> @@ -621,6 +627,11 @@ struct CounterCoverageMappingBuilder
>> 
>>   void VisitDecl(const Decl *D) {
>>     Stmt *Body = D->getBody();
>> +
>> +    // Do not propagate region counts into system headers.
>> +    if (Body && SM.isInSystemHeader(SM.getSpellingLoc(getStart(Body))))
>> +      return;
>> +
>>     propagateCounts(getRegionCounter(Body), Body);
>>   }
>> 
>> 
>> Removed: cfe/trunk/test/CoverageMapping/system_macro.c
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/system_macro.c?rev=276715&view=auto
>> ==============================================================================
>> --- cfe/trunk/test/CoverageMapping/system_macro.c (original)
>> +++ cfe/trunk/test/CoverageMapping/system_macro.c (removed)
>> @@ -1,23 +0,0 @@
>> -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name system_macro.c -o - %s | FileCheck %s
>> -
>> -#ifdef IS_SYSHEADER
>> -
>> -#pragma clang system_header
>> -#define Func(x) if (x) {}
>> -#define SomeType int
>> -
>> -#else
>> -
>> -#define IS_SYSHEADER
>> -#include __FILE__
>> -
>> -// CHECK-LABEL: doSomething:
>> -void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0
>> -  Func(x);
>> -  return;
>> -  SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0
>> -}
>> -
>> -int main() {}
>> -
>> -#endif
>> 
>> Copied: cfe/trunk/test/CoverageMapping/system_macro.cpp (from r276711, cfe/trunk/test/CoverageMapping/system_macro.c)
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/system_macro.cpp?p2=cfe/trunk/test/CoverageMapping/system_macro.cpp&p1=cfe/trunk/test/CoverageMapping/system_macro.c&r1=276711&r2=276716&rev=276716&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/CoverageMapping/system_macro.c (original)
>> +++ cfe/trunk/test/CoverageMapping/system_macro.cpp Mon Jul 25 19:24:59 2016
>> @@ -1,4 +1,4 @@
>> -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name system_macro.c -o - %s | FileCheck %s
>> +// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name system_macro.cpp -o - %s | FileCheck %s
>> 
>> #ifdef IS_SYSHEADER
>> 
>> @@ -11,13 +11,16 @@
>> #define IS_SYSHEADER
>> #include __FILE__
>> 
>> -// CHECK-LABEL: doSomething:
>> +// CHECK-LABEL: doSomething
>> void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0
>>   Func(x);
>>   return;
>>   SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0
>> }
>> 
>> -int main() {}
>> +// CHECK-LABEL: main
>> +int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+2]]:2 = #0
>> +  Func([] { return true; }());
>> +}
>> 
>> #endif
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list