Changes because the Terminator::getSuccessor function now FAILS if successor
authorChris Lattner <sabre@nondot.org>
Sat, 27 Apr 2002 03:15:45 +0000 (03:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 27 Apr 2002 03:15:45 +0000 (03:15 +0000)
IDX is out of range instead of returning null.

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

lib/Transforms/IPO/MutateStructTypes.cpp
lib/Transforms/Scalar/SCCP.cpp

index fcad5fa050bfed7d85eae298d0d3f78083a39c25..b5dd937f7ef5a083b1c228fbddd8eeb1bc73a411 100644 (file)
@@ -369,10 +369,15 @@ void MutateStructTypes::transformMethod(Function *m) {
         break;
       case Instruction::Br: {
         const BranchInst *BI = cast<BranchInst>(I);
-        NewI = new BranchInst(
-                           cast<BasicBlock>(ConvertValue(BI->getSuccessor(0))),
-                    cast_or_null<BasicBlock>(ConvertValue(BI->getSuccessor(1))),
-                              ConvertValue(BI->getCondition()));
+        if (BI->isConditional()) {
+          NewI =
+            new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0))),
+                           cast<BasicBlock>(ConvertValue(BI->getSuccessor(1))),
+                           ConvertValue(BI->getCondition()));
+        } else {
+          NewI = 
+            new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0))));
+        }
         break;
       }
       case Instruction::Switch:
index fd3daa5bef408d1146e5171222da9084b2b65a90..51a827d14bbefea7740edab54917d247bfdb215e 100644 (file)
@@ -397,8 +397,8 @@ void SCCP::visitBranchInst(BranchInst *BI) {
 void SCCP::visitSwitchInst(SwitchInst *SI) {
   InstVal &SCValue = getValueState(SI->getCondition());
   if (SCValue.isOverdefined()) {  // Overdefined condition?  All dests are exe
-    for(unsigned i = 0; BasicBlock *Succ = SI->getSuccessor(i); ++i)
-      markExecutable(Succ);
+    for(unsigned i = 0, E = SI->getNumSuccessors(); i != E; ++i)
+      markExecutable(SI->getSuccessor(i));
   } else if (SCValue.isConstant()) {
     Constant *CPV = SCValue.getConstant();
     // Make sure to skip the "default value" which isn't a value