<div dir="ltr">To make this clearer, I've reposted the loops below, replacing dyn_cast with cast. I've also added the assertion, which triggers in the bottom loop, but not the top.<div><br></div><div>-Rob</div><div>
<br></div><div><div style="font-family:arial,sans-serif;font-size:13px">===========================<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
<div>for (GlobalVariable **i = Globals.begin(), **e = Globals.end(); i != e; ++i) {</div><div><span style="white-space:pre-wrap"> </span>GlobalVariable *GV = *i;</div></div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px"> Constant *GEP = ConstantExpr::getGetElementPtr(...);<br></div><div style="font-family:arial,sans-serif;font-size:13px"> GV->replaceAllUsesWith(GEP);<br>
</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style><font face="arial, sans-serif">assert(GV->use_empty());</font><br></div><div style="font-family:arial,sans-serif;font-size:13px">===========================</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><div><div>for (GlobalVariable **i = Globals.begin(), **e = Globals.end(); i != e; ++i) {</div><div>
<span style="white-space:pre-wrap"> </span>GlobalVariable *GV = *i;</div></div><div><br></div><div> Constant *GEP = ConstantExpr::getGetElementPtr(...);<br></div><div><br></div><div><div> for (Value::use_iterator ui = GV->use_begin(); ui != GV->use_end(); ++ui) {</div>
<div> User *u = cast < User > (*ui);</div><div> u->replaceUsesOfWith(GV, GEP); </div></div><div> }</div></div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style><font face="arial, sans-serif">assert(GV->use_empty());</font><br>
</div><div style="font-family:arial,sans-serif;font-size:13px">===========================</div></div><div class="gmail_extra"><br></div></div>