<div dir="ltr"><div><div><div><div>Hi All,<br><br></div>I need to remove successors from every basic block to insert new ones<br><br></div>I tried this code, but it doesn't work<br><br><br> void RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {<br>
    assert(SuccNum < TI->getNumSuccessors() &&<br>       "Trying to remove a nonexistant successor!");<br><br>    // If our old successor block contains any PHI nodes, remove the entry in the<br>    // PHI nodes that comes from this branch...<br>
    //<br>    BasicBlock *BB = TI->getParent();<br>    TI->getSuccessor(SuccNum)->removePredecessor(BB);<br><br>    TerminatorInst *NewTI = 0;<br>    switch (TI->getOpcode()) {<br>    case Instruction::Br:<br>
      // If this is a conditional branch... convert to unconditional branch.<br>      if (TI->getNumSuccessors() == 2) {<br>    cast<BranchInst>(TI)->setUnconditionalDest(TI->getSuccessor(1-SuccNum));<br>      } else {                    // Otherwise convert to a return instruction...<br>
        Value *RetVal = 0;<br><br>    // Create a value to return... if the function doesn't return null...<br>    if (!(BB->getParent()->getReturnType())->isVoidTy())<br>      RetVal = Constant::getNullValue(BB->getParent()->getReturnType());<br>
    // Create the return...<br>    NewTI = 0;<br>      }<br>      break;<br><br>    case Instruction::Invoke:    // Should convert to call<br>    case Instruction::Switch:    // Should remove entry<br>    default:<br>    case Instruction::Ret:       // Cannot happen, has no successors!<br>
      assert(0 && "Unhandled terminator instruction type in RemoveSuccessor!");<br>      abort();<br>    }<br><br>    if (NewTI)   // If it's a different instruction, replace.<br>      ReplaceInstWithInst(TI, NewTI);<br>
  }<br><br><br></div>Could you please help me to know where is the problem ?<br></div>Thank you<br clear="all"><div><div><div><div><div><br>-- <br><div dir="ltr"><b style="color:rgb(32,18,77)"><span>     </span>Rasha Salah Omar<br>
<span>    </span> Msc Student at E-JUST<br><span>    </span> Demonestrator  at Faculty of Computers and Informatics<br><span>    </span> Benha University</b>
<p style="color:rgb(32,18,77);font-size:13px;font-family:arial,helvetica,clean,sans-serif;background-color:transparent;font-style:normal"><b><span>     e-mail: <a href="mailto:rasha.omar@ejust.edu.eg" target="_blank">rasha.omar@ejust.edu.eg</a></span></b></p>

<font size="4"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px;border-collapse:collapse;color:rgb(69,69,69)"><div style="padding:0px;display:block;line-height:normal">
<span style="font-size:20pt;color:rgb(0,176,80);font-family:Webdings">P</span><b><span style="font-size:11pt;color:rgb(0,176,80);font-family:sans-serif"> Please consider the environment before printing this email.</span></b></div>
</span></font><br></div>
</div></div></div></div></div></div>