diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 44bc7fbfdd37e..5c810cd332185 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -7165,6 +7165,9 @@ void CodeGenModule::AddDeferredUnusedCoverageMapping(Decl *D) { SourceManager &SM = getContext().getSourceManager(); if (LimitedCoverage && SM.getMainFileID() != SM.getFileID(D->getBeginLoc())) break; + if (!llvm::coverage::SystemHeadersCoverage && + SM.isInSystemHeader(D->getBeginLoc())) + break; DeferredEmptyCoverageMappingDecls.try_emplace(D, true); break; } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 6e6dfc4d5a642..cfcdb5911b581 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1044,13 +1044,17 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) { if (Fn->hasFnAttribute(llvm::Attribute::SkipProfile)) return; + SourceManager &SM = CGM.getContext().getSourceManager(); + if (!llvm::coverage::SystemHeadersCoverage && + SM.isInSystemHeader(D->getLocation())) + return; + setFuncName(Fn); mapRegionCounters(D); if (CGM.getCodeGenOpts().CoverageMapping) emitCounterRegionMapping(D); if (PGOReader) { - SourceManager &SM = CGM.getContext().getSourceManager(); loadRegionCounts(PGOReader, SM.isInMainFile(D->getLocation())); computeRegionCounts(D); applyFunctionAttributes(PGOReader, Fn); diff --git a/clang/test/CoverageMapping/system_macro.cpp b/clang/test/CoverageMapping/system_macro.cpp index 3909c17a9b5c6..38bbb2efb7075 100644 --- a/clang/test/CoverageMapping/system_macro.cpp +++ b/clang/test/CoverageMapping/system_macro.cpp @@ -5,9 +5,8 @@ // LL_CHECK: @__covrec_ // LL_W_SYS: [[PROFC:@.*__profc_.*SysTmpl.*]] = -// LL_WOSYS: [[PROFC:@.*__profc_.*SysTmpl.*]] = // LL_W_SYS: @{{.*}}__profd_{{.*}}SysTmpl{{.*}} = -// LL_WOSYS: @{{.*}}__profd_{{.*}}SysTmpl{{.*}} = +// LL_WOSYS-NOT: SysTmpl // LL_CHECK: @llvm.used = @@ -21,7 +20,7 @@ template bool SysTmpl() { return f; } // Check SysTmpl() is instrumented or not. // LL_W_SYS: load i64, ptr [[PROFC]], -// LL_WOSYS: load i64, ptr [[PROFC]], +// LL_WOSYS-NOT: load i64, ptr @__profc_ #else