Skip to content

Commit c067524

Browse files
[SHT_LLVM_BB_ADDR_MAP] Add assertion and clarify docstring (#77374)
This patch adds an assertion to readBBAddrMapImpl to confirm that PGOAnalyses and BBAddrMaps are of the same size when PGO information is requested (part of the API contract). This patch also updates the docstring for readBBAddrMap to better clarify what is guaranteed.
1 parent 76ffa8f commit c067524

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ class ELFObjectFileBase : public ObjectFile {
110110
Expected<std::vector<VersionEntry>> readDynsymVersions() const;
111111

112112
/// Returns a vector of all BB address maps in the object file. When
113-
// `TextSectionIndex` is specified, only returns the BB address maps
114-
// corresponding to the section with that index. When `PGOAnalyses`is
115-
// specified, the vector is cleared then filled with extra PGO data.
116-
// `PGOAnalyses` will always be the same length as the return value on
117-
// success, otherwise it is empty.
113+
/// `TextSectionIndex` is specified, only returns the BB address maps
114+
/// corresponding to the section with that index. When `PGOAnalyses`is
115+
/// specified (PGOAnalyses is not nullptr), the vector is cleared then filled
116+
/// with extra PGO data. `PGOAnalyses` will always be the same length as the
117+
/// return value when it is requested assuming no error occurs. Upon failure,
118+
/// `PGOAnalyses` will be emptied.
118119
Expected<std::vector<BBAddrMap>>
119120
readBBAddrMap(std::optional<unsigned> TextSectionIndex = std::nullopt,
120121
std::vector<PGOAnalysisMap> *PGOAnalyses = nullptr) const;

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@ Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(
830830
std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
831831
std::back_inserter(BBAddrMaps));
832832
}
833+
if (PGOAnalyses)
834+
assert(PGOAnalyses->size() == BBAddrMaps.size() &&
835+
"The same number of BBAddrMaps and PGOAnalysisMaps should be "
836+
"returned when PGO information is requested");
833837
return BBAddrMaps;
834838
}
835839

0 commit comments

Comments
 (0)