]> granicus.if.org Git - clang/commitdiff
[Coverage] Do not write out coverage mappings with zero entries
authorVedant Kumar <vsk@apple.com>
Tue, 26 Jul 2016 00:24:59 +0000 (00:24 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 26 Jul 2016 00:24:59 +0000 (00:24 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276716 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CoverageMappingGen.cpp
test/CoverageMapping/system_macro.cpp [moved from test/CoverageMapping/system_macro.c with 50% similarity]

index 4debc7e95065470a34c34a70e4c7485b58f21718..da6fa2a37a3ab0405f116b547fea5e4a09b1a61b 100644 (file)
@@ -352,6 +352,9 @@ struct EmptyCoverageMappingBuilder : public CoverageMappingBuilder {
     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);
   }
 
similarity index 50%
rename from test/CoverageMapping/system_macro.c
rename to test/CoverageMapping/system_macro.cpp
index bddc822b0d90bd73833bc8f3580a3d5e0ce69136..ce0da17ce06c9a0cd343e9095eb2711511fb9b54 100644 (file)
@@ -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
 
 #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