]> granicus.if.org Git - llvm/commitdiff
[RISCV] Don't acccess an invalidated iterator in RISCVInstrInfo::removeBranch
authorAlex Bradbury <asb@lowrisc.org>
Thu, 18 Jul 2019 03:23:47 +0000 (03:23 +0000)
committerAlex Bradbury <asb@lowrisc.org>
Thu, 18 Jul 2019 03:23:47 +0000 (03:23 +0000)
Issue found by ASan.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366397 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/RISCV/RISCVInstrInfo.cpp

index 2608906bb4308775c7c6d2ff249af85fdf273e0c..99c8d2ef73de594324ee561f275867633ac88844 100644 (file)
@@ -290,9 +290,9 @@ unsigned RISCVInstrInfo::removeBranch(MachineBasicBlock &MBB,
     return 0;
 
   // Remove the branch.
-  I->eraseFromParent();
   if (BytesRemoved)
     *BytesRemoved += getInstSizeInBytes(*I);
+  I->eraseFromParent();
 
   I = MBB.end();
 
@@ -303,9 +303,9 @@ unsigned RISCVInstrInfo::removeBranch(MachineBasicBlock &MBB,
     return 1;
 
   // Remove the branch.
-  I->eraseFromParent();
   if (BytesRemoved)
     *BytesRemoved += getInstSizeInBytes(*I);
+  I->eraseFromParent();
   return 2;
 }