[llvm] [Coverage] Guard against empty CountedRegions in findMainViewFileID (PR #189270)
Zile Xiong via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 29 11:18:19 PDT 2026
https://github.com/xiongzile updated https://github.com/llvm/llvm-project/pull/189270
>From 1611ce98aea6d5f8d8b2c24a31612ab2fa749201 Mon Sep 17 00:00:00 2001
From: Zile Xiong <xiongzile99 at gmail.com>
Date: Mon, 30 Mar 2026 02:03:54 +0800
Subject: [PATCH] [Coverage] Guard against empty CountedRegions in
findMainViewFileID
findMainViewFileID assumes that a function has at least one counted
region to infer its main view file. In practice, some inputs can reach
this path with an empty CountedRegions list, which leaves the function
without enough information to select a FileID.
Return std::nullopt early in that case instead of continuing with the
normal selection logic.
This is a defensive fix for the empty-region case observed in
https://github.com/llvm/llvm-project/issues/189169. Further
investigation may still be needed to understand why such functions are
produced and whether branch-only coverage records should also
participate in main view file selection.
---
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 4ce78fe6e3182..8b54374aa0b1c 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -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)
More information about the llvm-commits
mailing list