Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 9a40255

Browse files
committed
[Coverage] Ignore 'unused' functions with non-zero execution counts
Frontends emit 'unused' coverage mapping records for functions which are provably unused in a TU. These unused records contain a single counter with CounterKind::Zero. However, a function may be unused in one TU and used in another. When this happens, prefer the records with a full set of counters instead of arbitrarily picking the first loaded record. There is no impact on the single-TU case. In the multiple-TU case, this resolves issues causing a function to appear unused when it's not. Testing: check-{llvm,clang,compiler-rt} rdar://42981322 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339194 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 71a5ad4)
1 parent abac5d4 commit 9a40255

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,6 @@ Error CoverageMapping::loadFunctionRecord(
207207
else
208208
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
209209

210-
// Don't load records for (filenames, function) pairs we've already seen.
211-
auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
212-
Record.Filenames.end());
213-
if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
214-
return Error::success();
215-
216210
CounterMappingContext Ctx(Record.Expressions);
217211

218212
std::vector<uint64_t> Counts;
@@ -230,6 +224,15 @@ Error CoverageMapping::loadFunctionRecord(
230224

231225
assert(!Record.MappingRegions.empty() && "Function has no regions");
232226

227+
// This coverage record is a zero region for a function that's unused in
228+
// some TU, but used in a different TU. Ignore it. The coverage maps from the
229+
// the other TU will either be loaded (providing full region counts) or they
230+
// won't (in which case we don't unintuitively report functions as uncovered
231+
// when they have non-zero counts in the profile).
232+
if (Record.MappingRegions.size() == 1 &&
233+
Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
234+
return Error::success();
235+
233236
FunctionRecord Function(OrigFuncName, Record.Filenames);
234237
for (const auto &Region : Record.MappingRegions) {
235238
Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
@@ -240,6 +243,12 @@ Error CoverageMapping::loadFunctionRecord(
240243
Function.pushRegion(Region, *ExecutionCount);
241244
}
242245

246+
// Don't create records for (filenames, function) pairs we've already seen.
247+
auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
248+
Record.Filenames.end());
249+
if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
250+
return Error::success();
251+
243252
Functions.push_back(std::move(Function));
244253
return Error::success();
245254
}

0 commit comments

Comments
 (0)