[PATCH] [AArch64] fix an invalid-iterator-use bug.
    Sanjoy Das 
    sanjoy at playingwithpointers.com
       
    Sun Mar  1 15:10:52 PST 2015
    
    
  
Hi t.p.northover, bkramer, grosbach,
In AArch64PromoteConstant::appendAndTransferDominatedUses,
`InsertPts[NewPt]` invalidates IPI.  Therefore, `InsertPts[NewPt] =
std::move(IPI->second)` is not legal.
This was caught by running `make check` with
http://reviews.llvm.org/D7931.
http://reviews.llvm.org/D7988
Files:
  lib/Target/AArch64/AArch64PromoteConstant.cpp
Index: lib/Target/AArch64/AArch64PromoteConstant.cpp
===================================================================
--- lib/Target/AArch64/AArch64PromoteConstant.cpp
+++ lib/Target/AArch64/AArch64PromoteConstant.cpp
@@ -189,9 +189,11 @@
     IPI->second.push_back(&Use);
     // Transfer the dominated uses of IPI to NewPt
     // Inserting into the DenseMap may invalidate existing iterator.
-    // Keep a copy of the key to find the iterator to erase.
+    // Keep a copy of the key to find the iterator to erase.  Keep a copy of the
+    // value so that we don't have to dereference IPI->second.
     Instruction *OldInstr = IPI->first;
-    InsertPts[NewPt] = std::move(IPI->second);
+    Uses OldUses = std::move(IPI->second);
+    InsertPts[NewPt] = std::move(OldUses);
     // Erase IPI.
     InsertPts.erase(OldInstr);
   }
EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7988.20968.patch
Type: text/x-patch
Size: 839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150301/5caa06e3/attachment.bin>
    
    
More information about the llvm-commits
mailing list