[llvm-cov] Guard against empty CountedRegions in findMainViewFileID (#189270)
When processing coverage generated from branch coverage mode, some functions can reach findMainViewFileID with an empty CountedRegions list. In that case the current logic still proceeds to infer the main view file, even though there is no regular counted region available to do so. Return std::nullopt early when CountedRegions is empty. This was observed when reproducing issue #189169 with: cargo llvm-cov --lib --branch The issue appears related to branch-only coverage information being recorded separately in CountedBranchRegions, while findMainViewFileID currently only consults CountedRegions. This patch is a defensive fix for the empty-region case; further investigation may still be needed to determine whether branch regions should participate in main view file selection. Co-authored-by: Zile Xiong <xiongzile99@gmail.com>
This commit is contained in:
parent
9033e872fd
commit
d917027334
@ -1436,6 +1436,8 @@ static SmallBitVector gatherFileIDs(StringRef SourceFile,
|
||||
/// Return the ID of the file where the definition of the function is located.
|
||||
static std::optional<unsigned>
|
||||
findMainViewFileID(const FunctionRecord &Function) {
|
||||
if (Function.CountedRegions.empty())
|
||||
return std::nullopt;
|
||||
SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
|
||||
for (const auto &CR : Function.CountedRegions)
|
||||
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,32 @@
|
||||
_RNCNvNtCsdlUpERXMHlK_14llvm_cov_crash5testss_4test0B5_
|
||||
# Func Hash:
|
||||
16906217776502244560
|
||||
# Num Counters:
|
||||
1
|
||||
# Counter Values:
|
||||
1
|
||||
|
||||
_RNCNvXCsdlUpERXMHlK_14llvm_cov_crashNtB4_4ImplNtB4_5Trait6method0B4_
|
||||
# Func Hash:
|
||||
8277137360535214580
|
||||
# Num Counters:
|
||||
1
|
||||
# Counter Values:
|
||||
1
|
||||
|
||||
_RNvNtCsdlUpERXMHlK_14llvm_cov_crash5testss_4test
|
||||
# Func Hash:
|
||||
16906217776502244560
|
||||
# Num Counters:
|
||||
1
|
||||
# Counter Values:
|
||||
1
|
||||
|
||||
_RNvXCsdlUpERXMHlK_14llvm_cov_crashNtB2_4ImplNtB2_5Trait6method
|
||||
# Func Hash:
|
||||
8277137360535214580
|
||||
# Num Counters:
|
||||
1
|
||||
# Counter Values:
|
||||
1
|
||||
|
||||
16
llvm/test/tools/llvm-cov/main-view-fileid-regression.test
Normal file
16
llvm/test/tools/llvm-cov/main-view-fileid-regression.test
Normal file
@ -0,0 +1,16 @@
|
||||
# These inputs were derived from a Rust reproducer (see llvm#189169)
|
||||
# using cargo llvm-cov --lib --branch.
|
||||
#
|
||||
# The generated coverage data was converted into .proftext and
|
||||
# .covmapping files and checked in for this regression test.
|
||||
|
||||
REQUIRES: zlib
|
||||
RUN: llvm-profdata merge %S/Inputs/main-view-fileid-regression.proftext -o %t.profdata
|
||||
RUN: llvm-cov report %S/Inputs/main-view-fileid-regression.covmapping \
|
||||
RUN: -instr-profile=%t.profdata \
|
||||
RUN: 2>/dev/null | FileCheck %s
|
||||
|
||||
CHECK: Filename
|
||||
CHECK: lib.rs
|
||||
CHECK: TOTAL
|
||||
CHECK: 100.00%
|
||||
Loading…
x
Reference in New Issue
Block a user