fix PR9523, a crash in looprotate on a non-canonical loop made out of indirectbr.
authorChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2011 07:25:58 +0000 (07:25 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2011 07:25:58 +0000 (07:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129203 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopRotation.cpp
test/Transforms/LoopRotate/crash.ll

index 95e15784df2c8a950bd0200f6a21b20a0a7525b4..e7b1a031f848aedfacfd7fed124a3ea9272337f3 100644 (file)
@@ -184,7 +184,11 @@ bool LoopRotate::rotateLoop(Loop *L) {
   // Now, this loop is suitable for rotation.
   BasicBlock *OrigPreheader = L->getLoopPreheader();
   BasicBlock *OrigLatch = L->getLoopLatch();
-  assert(OrigPreheader && OrigLatch && "Loop not in canonical form?");
+  
+  // If the loop could not be converted to canonical form, it must have an
+  // indirectbr in it, just give up.
+  if (OrigPreheader == 0 || OrigLatch == 0)
+    return false;
 
   // Anything ScalarEvolution may know about this loop or the PHI nodes
   // in its header will soon be invalidated.
index 9dc9862d150ab68b24a01fb5b579ed01328bb458..16a6868f8ff14f91923258df994daa7de5b797a4 100644 (file)
@@ -137,3 +137,19 @@ bb17:              ; preds = %bb15
 }
 
 
+
+
+; PR9523 - Non-canonical loop.
+define void @test7(i8* %P) nounwind {
+entry:
+  indirectbr i8* %P, [label %"3", label %"5"]
+
+"3":                                              ; preds = %"4", %entry
+  br i1 undef, label %"5", label %"4"
+
+"4":                                              ; preds = %"3"
+  br label %"3"
+
+"5":                                              ; preds = %"3", %entry
+  ret void
+}