[X86] Fix sanitizer bot failure from 344085
authorRong Xu <xur@google.com>
Tue, 9 Oct 2018 23:10:56 +0000 (23:10 +0000)
committerRong Xu <xur@google.com>
Tue, 9 Oct 2018 23:10:56 +0000 (23:10 +0000)
Fix the memory issue exposed by sanitizer.

llvm-svn: 344092

llvm/lib/Target/X86/X86CondBrFolding.cpp

index 9a5ae70..8b9ef20 100644 (file)
@@ -424,8 +424,9 @@ bool X86CondBrFolding::optimize() {
   }
   NumFixedCondBrs += RemoveList.size();
   for (auto MBBI : RemoveList) {
-    for (auto *Succ : MBBI->successors())
-      MBBI->removeSuccessor(Succ);
+    while (!MBBI->succ_empty())
+      MBBI->removeSuccessor(MBBI->succ_end() - 1);
+
     MBBI->eraseFromParent();
   }