Commit 7bf9e46f authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r276716:

------------------------------------------------------------------------
r276716 | vedantk | 2016-07-25 17:24:59 -0700 (Mon, 25 Jul 2016) | 10 lines

[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.
------------------------------------------------------------------------

llvm-svn: 276801
parent 79d0e34a
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -351,6 +351,9 @@ struct EmptyCoverageMappingBuilder : public CoverageMappingBuilder {
    gatherFileIDs(FileIDMapping);
    emitSourceRegions();

    if (MappingRegions.empty())
      return;

    CoverageMappingWriter Writer(FileIDMapping, None, MappingRegions);
    Writer.write(OS);
  }
@@ -604,6 +607,9 @@ struct CounterCoverageMappingBuilder
    emitExpansionRegions();
    gatherSkippedRegions();

    if (MappingRegions.empty())
      return;

    CoverageMappingWriter Writer(VirtualFileMapping, Builder.getExpressions(),
                                 MappingRegions);
    Writer.write(OS);
@@ -620,6 +626,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);
  }

+6 −3
Original line number Diff line number Diff line
// 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