[BOLT] Make sure IOAddressMap exist before lookup (NFC) (#183184)

`BinaryFunction::translateInputToOutputAddress()` contains fallback
logic in case that querying `IOAddressMap` doesn't yield an output
address. Because this function could be called in scenarios where
`IOAddressMap` won't be set up, we should check if the map actually
exists before lookup.
This commit is contained in:
YongKang Zhu
2026-03-01 23:27:39 -08:00
committed by GitHub
parent b4b32e88dd
commit 14bcb1a009
2 changed files with 5 additions and 2 deletions

View File

@@ -1560,6 +1560,7 @@ public:
return Streamer;
}
bool hasIOAddressMap() const { return IOAddressMap.has_value(); }
void setIOAddressMap(AddressMap Map) { IOAddressMap = std::move(Map); }
const AddressMap &getIOAddressMap() const {
assert(IOAddressMap && "Address map not set yet");

View File

@@ -4631,8 +4631,10 @@ uint64_t BinaryFunction::translateInputToOutputAddress(uint64_t Address) const {
// Check if the address is associated with an instruction that is tracked
// by address translation.
if (auto OutputAddress = BC.getIOAddressMap().lookup(Address))
return *OutputAddress;
if (BC.hasIOAddressMap()) {
if (auto OutputAddress = BC.getIOAddressMap().lookup(Address))
return *OutputAddress;
}
// FIXME: #18950828 - we rely on relative offsets inside basic blocks to stay
// intact. Instead we can use pseudo instructions and/or annotations.