Skip to content

Commit 93205af

Browse files
committed
[Coverage] Do not map regions from system headers
Do not assign source regions located within system headers file ID's, and do not construct counter mapping regions out of them. This makes coverage reports less cluttered and less mysterious. E.g using the "assert" macro doesn't cause assert.h to appear in reports, and it no longer shows the "assertion failed" branch as an uncovered region. It also makes coverage mapping sections a bit smaller (e.g a 1% reduction in a stage2 build of bin/llvm-as). llvm-svn: 275121
1 parent c468bb8 commit 93205af

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ class CoverageMappingBuilder {
172172
if (!Visited.insert(File).second)
173173
continue;
174174

175+
// Do not map FileID's associated with system headers.
176+
if (SM.isInSystemHeader(SM.getSpellingLoc(Loc)))
177+
continue;
178+
175179
unsigned Depth = 0;
176180
for (SourceLocation Parent = getIncludeOrExpansionLoc(Loc);
177181
Parent.isValid(); Parent = getIncludeOrExpansionLoc(Parent))
@@ -251,6 +255,10 @@ class CoverageMappingBuilder {
251255
SourceLocation LocStart = Region.getStartLoc();
252256
assert(SM.getFileID(LocStart).isValid() && "region in invalid file");
253257

258+
// Ignore regions from system headers.
259+
if (SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
260+
continue;
261+
254262
auto CovFileID = getCoverageFileID(LocStart);
255263
// Ignore regions that don't have a file, such as builtin macros.
256264
if (!CovFileID)

clang/test/CoverageMapping/system_macro.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
// CHECK-LABEL: doSomething:
1515
void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0
16-
Func(x); // CHECK: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:7
16+
Func(x);
1717
return;
18-
// CHECK: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:11
1918
SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0
2019
}
2120

0 commit comments

Comments
 (0)