Skip to content

[SHT_LLVM_BB_ADDR_MAP] Add assertion and clarify docstring #77374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ class ELFObjectFileBase : public ObjectFile {
Expected<std::vector<VersionEntry>> readDynsymVersions() const;

/// Returns a vector of all BB address maps in the object file. When
// `TextSectionIndex` is specified, only returns the BB address maps
// corresponding to the section with that index. When `PGOAnalyses`is
// specified, the vector is cleared then filled with extra PGO data.
// `PGOAnalyses` will always be the same length as the return value on
// success, otherwise it is empty.
/// `TextSectionIndex` is specified, only returns the BB address maps
/// corresponding to the section with that index. When `PGOAnalyses`is
/// specified (PGOAnalyses is not nullptr), the vector is cleared then filled
/// with extra PGO data. `PGOAnalyses` will always be the same length as the
/// return value when it is requested assuming no error occurs. Upon failure,
/// `PGOAnalyses` will be emptied.
Expected<std::vector<BBAddrMap>>
readBBAddrMap(std::optional<unsigned> TextSectionIndex = std::nullopt,
std::vector<PGOAnalysisMap> *PGOAnalyses = nullptr) const;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Object/ELFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,10 @@ Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(
std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(),
std::back_inserter(BBAddrMaps));
}
if (PGOAnalyses)
assert(PGOAnalyses->size() == BBAddrMaps.size() &&
"The same number of BBAddrMaps and PGOAnalysisMaps should be "
"returned when PGO information is requested");
return BBAddrMaps;
}

Expand Down