gulfem created this revision. Herald added a project: All. gulfem requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D143304 Files: clang/lib/CodeGen/CoverageMappingGen.cpp clang/test/CoverageMapping/system_macro.cpp Index: clang/test/CoverageMapping/system_macro.cpp =================================================================== --- clang/test/CoverageMapping/system_macro.cpp +++ clang/test/CoverageMapping/system_macro.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name system_macro.cpp -o - %s | FileCheck %s +// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm -system-headers-coverage -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 @@ -13,8 +13,9 @@ // CHECK-LABEL: doSomething void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0 - Func(x); + Func(x); // CHECK: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:7 return; + // CHECK: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:11 SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0 } Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -37,6 +37,11 @@ "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 @@ 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 @@ 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 @@ 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
Index: clang/test/CoverageMapping/system_macro.cpp =================================================================== --- clang/test/CoverageMapping/system_macro.cpp +++ clang/test/CoverageMapping/system_macro.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name system_macro.cpp -o - %s | FileCheck %s +// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm -system-headers-coverage -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 @@ -13,8 +13,9 @@ // CHECK-LABEL: doSomething void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0 - Func(x); + Func(x); // CHECK: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:7 return; + // CHECK: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:11 SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0 } Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -37,6 +37,11 @@ "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 @@ 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 @@ 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 @@ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits