[llvm-commits] [llvm-gcc-4.2] r94759 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Stuart Hastings stuart at apple.com
Thu Jan 28 15:08:38 PST 2010


Author: stuart
Date: Thu Jan 28 17:08:38 2010
New Revision: 94759

URL: http://llvm.org/viewvc/llvm-project?rev=94759&view=rev
Log:
Fix an off-by-one error when the insertion point wanders past a
terminating branch.  Radar 7548753.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=94759&r1=94758&r2=94759&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Thu Jan 28 17:08:38 2010
@@ -2978,6 +2978,7 @@
   if (Instruction *I = dyn_cast<Instruction>(FirstVal)) {
     InsertPt = I;                      // Insert after the init instruction.
 
+    bool InsertPtFinal = false;
     // If the instruction is an alloca in the entry block, the insert point
     // will be before the alloca.  Advance to the AllocaInsertionPoint if we are
     // before it.
@@ -2987,18 +2988,22 @@
         if (&*CI == AllocaInsertionPoint) {
           InsertPt = AllocaInsertionPoint;
           ++InsertPt;
+	  InsertPtFinal = true;		// This is the spot; stop searching.
           break;
         }
       }
     }
 
-    // If the instruction is an invoke, the init is inserted on the normal edge.
-    if (InvokeInst *II = dyn_cast<InvokeInst>(InsertPt)) {
-      InsertPt = II->getNormalDest()->begin();
-      while (isa<PHINode>(InsertPt))
-        ++InsertPt;
-    } else
-      ++InsertPt; // Insert after the init instruction.
+    if (!InsertPtFinal) {
+      // If the instruction is an invoke, the init is inserted on the normal edge.
+      if (InvokeInst *II = dyn_cast<InvokeInst>(InsertPt)) {
+	InsertPt = II->getNormalDest()->begin();
+	while (isa<PHINode>(InsertPt))
+	  ++InsertPt;
+      }
+      else
+	++InsertPt; // Insert after the init instruction.
+    }
   } else {
     InsertPt = AllocaInsertionPoint;   // Insert after the allocas.
     ++InsertPt;





More information about the llvm-commits mailing list