[clang] [Coverage] Map regions from system headers (PR #76950)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 04:39:18 PST 2024


https://github.com/ManuelvOK updated https://github.com/llvm/llvm-project/pull/76950

>From 1762695354c172bb35b97017b2706d8d476121e1 Mon Sep 17 00:00:00 2001
From: Manuel Kalettka <manuel.kalettka at kernkonzept.com>
Date: Wed, 3 Jan 2024 16:59:00 +0100
Subject: [PATCH] [Coverage] Map regions from system headers

In 2155195, the "system-headers-coverage" option has been added but
not used in all necessary places.
---
 clang/lib/CodeGen/CodeGenPGO.cpp         | 4 +++-
 clang/lib/CodeGen/CoverageMappingGen.cpp | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index d68844d476eb4e..5d7c3847745762 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -28,6 +28,8 @@ static llvm::cl::opt<bool>
                          llvm::cl::desc("Enable value profiling"),
                          llvm::cl::Hidden, llvm::cl::init(false));
 
+extern llvm::cl::opt<bool> SystemHeadersCoverage;
+
 using namespace clang;
 using namespace CodeGen;
 
@@ -1022,7 +1024,7 @@ bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getBeginLoc();
-  return SM.isInSystemHeader(Loc);
+  return !SystemHeadersCoverage && SM.isInSystemHeader(Loc);
 }
 
 void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 8b5e6c4ad8272f..5eca00f22bb83c 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -37,7 +37,7 @@ static llvm::cl::opt<bool> EmptyLineCommentCoverage(
                    "disable it on test)"),
     llvm::cl::init(true), llvm::cl::Hidden);
 
-static llvm::cl::opt<bool> SystemHeadersCoverage(
+llvm::cl::opt<bool> SystemHeadersCoverage(
     "system-headers-coverage",
     llvm::cl::desc("Enable collecting coverage from system headers"),
     llvm::cl::init(false), llvm::cl::Hidden);



More information about the cfe-commits mailing list