From: Ali Saidi Date: Thu, 10 May 2012 23:04:27 +0000 (-0500) Subject: gem5: fix some iterator use and erase bugs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4f66bcdd2e2cf983f66fe745eaa27698e90d0d60;p=gem5.git gem5: fix some iterator use and erase bugs --- diff --git a/src/cpu/pc_event.cc b/src/cpu/pc_event.cc index 9cf63f7d3..2b54ee5fb 100644 --- a/src/cpu/pc_event.cc +++ b/src/cpu/pc_event.cc @@ -56,13 +56,18 @@ PCEventQueue::remove(PCEvent *event) { int removed = 0; range_t range = equal_range(event); - for (iterator i = range.first; i != range.second; ++i) { + iterator i = range.first; + while (i != range.second && + i != pc_map.end()) { if (*i == event) { DPRINTF(PCEvent, "PC based event removed at %#x: %s\n", event->pc(), event->descr()); - pc_map.erase(i); + i = pc_map.erase(i); ++removed; + } else { + i++; } + } return removed > 0; diff --git a/src/mem/cache/prefetch/base.cc b/src/mem/cache/prefetch/base.cc index 4d1f7c81c..f3ac5f046 100644 --- a/src/mem/cache/prefetch/base.cc +++ b/src/mem/cache/prefetch/base.cc @@ -182,7 +182,7 @@ BasePrefetcher::notify(PacketPtr &pkt, Tick time) pfRemovedMSHR++; delete (*iter)->req; delete (*iter); - pf.erase(iter); + iter = pf.erase(iter); if (pf.empty()) cache->deassertMemSideBusRequest(BaseCache::Request_PF); } @@ -194,15 +194,17 @@ BasePrefetcher::notify(PacketPtr &pkt, Tick time) // Needed for serial calculators like GHB if (serialSquash) { iter = pf.end(); - iter--; + if (iter != pf.begin()) + iter--; while (!pf.empty() && ((*iter)->time >= time)) { pfSquashed++; DPRINTF(HWPrefetch, "Squashing old prefetch addr: 0x%x\n", (*iter)->getAddr()); delete (*iter)->req; delete (*iter); - pf.erase(iter); - iter--; + iter = pf.erase(iter); + if (iter != pf.begin()) + iter--; } if (pf.empty()) cache->deassertMemSideBusRequest(BaseCache::Request_PF);