[llvm] r237974 - [PPC] Correct iterator bug in PPCTLSDynamicCall

Hal Finkel hfinkel at anl.gov
Thu May 21 16:45:49 PDT 2015


Author: hfinkel
Date: Thu May 21 18:45:49 2015
New Revision: 237974

URL: http://llvm.org/viewvc/llvm-project?rev=237974&view=rev
Log:
[PPC] Correct iterator bug in PPCTLSDynamicCall

Unfortunately, I can't reduce a small test case for this (although compiling
mpfr-3.1.2 with -O2 -mcpu=a2 would fairly reliably trigger a crash), but the
problem is fairly clear (at least once you know you're looking for one). If the
TLS instruction being replaced was at the end of the block, we'd increment the
iterator past it (so it would then point to MBB.end()), and then we'd increment
it again as part of the for statement, thus overrunning the end of the list.
Don't do that.

Modified:
    llvm/trunk/lib/Target/PowerPC/PPCTLSDynamicCall.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCTLSDynamicCall.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCTLSDynamicCall.cpp?rev=237974&r1=237973&r2=237974&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCTLSDynamicCall.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCTLSDynamicCall.cpp Thu May 21 18:45:49 2015
@@ -55,14 +55,16 @@ protected:
       bool Is64Bit = MBB.getParent()->getSubtarget<PPCSubtarget>().isPPC64();
 
       for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end();
-           I != IE; ++I) {
+           I != IE;) {
         MachineInstr *MI = I;
 
         if (MI->getOpcode() != PPC::ADDItlsgdLADDR &&
             MI->getOpcode() != PPC::ADDItlsldLADDR &&
             MI->getOpcode() != PPC::ADDItlsgdLADDR32 &&
-            MI->getOpcode() != PPC::ADDItlsldLADDR32)
+            MI->getOpcode() != PPC::ADDItlsldLADDR32) {
+          ++I;
           continue;
+        }
 
         DEBUG(dbgs() << "TLS Dynamic Call Fixup:\n    " << *MI;);
 





More information about the llvm-commits mailing list