aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CoverageMappingGen.cpp
diff options
context:
space:
mode:
authorGulfem Savrun Yeniceri <gulfem@google.com>2023-01-27 18:02:26 +0000
committerGulfem Savrun Yeniceri <gulfem@google.com>2023-02-06 18:12:01 +0000
commit2155195131a57f2f01e7cfabb85bb027518c2dc6 (patch)
tree41b4a838d1d1206b486692735da853d9ae0313be /clang/lib/CodeGen/CoverageMappingGen.cpp
parent8028263c41e335bc96c40402f8ab44ad405023de (diff)
downloadllvm-2155195131a57f2f01e7cfabb85bb027518c2dc6.zip
llvm-2155195131a57f2f01e7cfabb85bb027518c2dc6.tar.gz
llvm-2155195131a57f2f01e7cfabb85bb027518c2dc6.tar.bz2
[Coverage] Map regions from system headers
Originally, the following commit removed mapping coverage regions for system headers: https://github.com/llvm/llvm-project/commit/93205af066341a53733046894bd75c72c99566db It might be viable and useful to collect coverage from system headers in some systems. This patch adds --system-headers-coverage option (disabled by default) to enable collecting coverage from system headers. Differential Revision: https://reviews.llvm.org/D143304
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r--clang/lib/CodeGen/CoverageMappingGen.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 101cd6a..56ff364 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -37,6 +37,11 @@ static llvm::cl::opt<bool> EmptyLineCommentCoverage(
"disable it on test)"),
llvm::cl::init(true), llvm::cl::Hidden);
+static llvm::cl::opt<bool> SystemHeadersCoverage(
+ "system-headers-coverage",
+ llvm::cl::desc("Enable collecting coverage from system headers"),
+ llvm::cl::init(false), llvm::cl::Hidden);
+
using namespace clang;
using namespace CodeGen;
using namespace llvm::coverage;
@@ -301,8 +306,9 @@ public:
if (!Visited.insert(File).second)
continue;
- // Do not map FileID's associated with system headers.
- if (SM.isInSystemHeader(SM.getSpellingLoc(Loc)))
+ // Do not map FileID's associated with system headers unless collecting
+ // coverage from system headers is explicitly enabled.
+ if (!SystemHeadersCoverage && SM.isInSystemHeader(SM.getSpellingLoc(Loc)))
continue;
unsigned Depth = 0;
@@ -416,8 +422,10 @@ public:
SourceLocation LocStart = Region.getBeginLoc();
assert(SM.getFileID(LocStart).isValid() && "region in invalid file");
- // Ignore regions from system headers.
- if (SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
+ // Ignore regions from system headers unless collecting coverage from
+ // system headers is explicitly enabled.
+ if (!SystemHeadersCoverage &&
+ SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
continue;
auto CovFileID = getCoverageFileID(LocStart);
@@ -1000,8 +1008,10 @@ 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))))
+ // Do not propagate region counts into system headers unless collecting
+ // coverage from system headers is explicitly enabled.
+ if (!SystemHeadersCoverage && Body &&
+ SM.isInSystemHeader(SM.getSpellingLoc(getStart(Body))))
return;
// Do not visit the artificial children nodes of defaulted methods. The