[BOLT] Fix a bug related to iterators in ReorderData pass
If `Itr` is the last element and then `std::next(Itr)` will be `Range.end()`, so that the statement `std::next(Itr)->second` is a UB. Reviewed By: yota9, maksfb Differential Revision: https://reviews.llvm.org/D159177
This commit is contained in:
parent
39f6a31eaa
commit
9c99e9fd68
@ -413,17 +413,17 @@ bool ReorderData::markUnmoveableSymbols(BinaryContext &BC,
|
||||
auto Range = BC.getBinaryDataForSection(Section);
|
||||
bool FoundUnmoveable = false;
|
||||
for (auto Itr = Range.begin(); Itr != Range.end(); ++Itr) {
|
||||
BinaryData *Next =
|
||||
std::next(Itr) != Range.end() ? std::next(Itr)->second : nullptr;
|
||||
if (Itr->second->getName().startswith("PG.")) {
|
||||
BinaryData *Prev =
|
||||
Itr != Range.begin() ? std::prev(Itr)->second : nullptr;
|
||||
BinaryData *Next = Itr != Range.end() ? std::next(Itr)->second : nullptr;
|
||||
bool PrevIsPrivate = Prev && isPrivate(Prev);
|
||||
bool NextIsPrivate = Next && isPrivate(Next);
|
||||
if (isPrivate(Itr->second) && (PrevIsPrivate || NextIsPrivate))
|
||||
Itr->second->setIsMoveable(false);
|
||||
} else {
|
||||
// check for overlapping symbols.
|
||||
BinaryData *Next = Itr != Range.end() ? std::next(Itr)->second : nullptr;
|
||||
if (Next && Itr->second->getEndAddress() != Next->getAddress() &&
|
||||
Next->containsAddress(Itr->second->getEndAddress())) {
|
||||
Itr->second->setIsMoveable(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user