[02/10] Android: erase the stl in iterator loop, must update the iterator.

Submitted by Yang, Rong R on May 19, 2016, 8:37 a.m.

Details

Message ID 1463647036-25545-2-git-send-email-rong.r.yang@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 2 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Yang, Rong R May 19, 2016, 8:37 a.m.
Otherwize, may cause crash in android.

Signed-off-by: Yang Rong <rong.r.yang@intel.com>
---
 backend/src/backend/gen_reg_allocation.cpp |  8 ++++----
 backend/src/llvm/llvm_gen_backend.cpp      | 16 ++++++++++------
 2 files changed, 14 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/backend/src/backend/gen_reg_allocation.cpp b/backend/src/backend/gen_reg_allocation.cpp
index da3dac0..00c341e 100644
--- a/backend/src/backend/gen_reg_allocation.cpp
+++ b/backend/src/backend/gen_reg_allocation.cpp
@@ -703,15 +703,15 @@  namespace gbe
       set<const ir::BasicBlock *> liveOutSet01;
       set<const ir::BasicBlock *> workSet(liveInSet01.begin(), liveInSet01.end());
       while(workSet.size()) {
-        for(auto bb : workSet) {
-          for(auto predBB : bb->getPredecessorSet()) {
+        for (auto bb = workSet.begin(); bb != workSet.end(); ) {
+          for(auto predBB : (*bb)->getPredecessorSet()) {
             liveOutSet01.insert(predBB);
-            if (liveInSet01.contains(predBB))
+            if (liveInSet01.find(predBB) != liveInSet01.end())
               continue;
             liveInSet01.insert(predBB);
             workSet.insert(predBB);
           }
-          workSet.erase(bb);
+          bb = workSet.erase(bb);
         }
       }
       int32_t maxID = 0;
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 59a58c5..46d5564 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -2436,13 +2436,16 @@  namespace gbe
     // Do multi pass redundant phi copy elimination based on the global interfering information.
     // FIXME, we don't need to re-compute the whole DAG for each pass.
     while (curRedundant->size() > 0) {
-      for (auto &pair : *curRedundant) {
-        auto phiCopySrc = pair.first;
-        auto phiCopy = pair.second;
+      //for (auto &pair = *curRedundant) {
+      for (auto pair = curRedundant->begin(); pair != curRedundant->end(); ) {
+        auto phiCopySrc = pair->first;
+        auto phiCopy = pair->second;
         if (replacedRegs.find(phiCopy) != replacedRegs.end() ||
             revReplacedRegs.find(phiCopy) != revReplacedRegs.end() ||
-            revReplacedRegs.find(phiCopySrc) != revReplacedRegs.end())
+            revReplacedRegs.find(phiCopySrc) != revReplacedRegs.end()) {
+          pair++;
           continue;
+        }
         if (!dag->interfere(liveness, phiCopySrc, phiCopy)) {
           const ir::DefSet *phiCopySrcDef = dag->getRegDef(phiCopySrc);
           const ir::UseSet *phiCopySrcUse = dag->getRegUse(phiCopySrc);
@@ -2458,8 +2461,9 @@  namespace gbe
 
           replacedRegs.insert(std::make_pair(phiCopySrc, phiCopy));
           revReplacedRegs.insert(std::make_pair(phiCopy, phiCopySrc));
-          curRedundant->erase(phiCopySrc);
-        }
+          curRedundant->erase(pair++);
+        } else
+          pair++;
       }
 
       if (replacedRegs.size() != 0) {