<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Thanks.</div><div><br></div><div><br></div><div>I try to delete function like this (<span class="Apple-style-span" style="color: rgb(23, 22, 201); font-family: Monaco; font-size: 11px; ">rta_IsFunctionVisited</span><span class="Apple-style-span" style="color: rgb(23, 22, 201); font-family: Monaco; font-size: 11px; "><span style="color: rgb(0, 0, 0); ">.find - set of good functions</span></span>) :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(81, 145, 116); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">              </span></span>// delete dead functions</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">            </span><span style="color: #910e66">for</span> (<span style="color: #056243">Module</span>::<span style="color: #056243">iterator</span> Fx = <span style="color: #1716c9">M</span>->begin(), FE = <span style="color: #1716c9">M</span>->end(); Fx!=FE; Fx++) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(23, 22, 201); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                      </span></span><span style="color: #910e66">if</span><span style="color: #000000"> (</span>rta_IsFunctionVisited<span style="color: #000000">.find(Fx)==</span>rta_IsFunctionVisited<span style="color: #000000">.end()) {</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                          </span>Fx->replaceAllUsesWith(<span style="color: #056243">UndefValue</span>::get(Fx->getType()));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                  </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">         </span><span style="color: #910e66">for</span> (<span style="color: #056243">CallGraph</span>::<span style="color: #056243">iterator</span> CGN = CG.begin(); CGN!=CG.end(); CGN++) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                 </span><span style="color: #910e66">if</span> (<span style="color: #1716c9">rta_IsFunctionVisited</span>.find(CGN->second->getFunction())==<span style="color: #1716c9">rta_IsFunctionVisited</span>.end()) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                           </span>CGN->second->removeAllCalledFunctions();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                   </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">         </span><span style="color: #910e66">for</span> (<span style="color: #056243">Module</span>::<span style="color: #056243">iterator</span> Fx = <span style="color: #1716c9">M</span>->begin(), FE = <span style="color: #1716c9">M</span>->end(); Fx!=FE;) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(23, 22, 201); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                   </span></span><span style="color: #910e66">if</span><span style="color: #000000"> (</span>rta_IsFunctionVisited<span style="color: #000000">.find(Fx)==</span>rta_IsFunctionVisited<span style="color: #000000">.end()) {</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                          </span><span style="color: #056243">CallGraphNode</span> *CGN = CG.getOrInsertFunction(Fx);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                               </span>CG.removeFunctionFromModule(Fx);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                         </span>wasChanged=<span style="color: #910e66">true</span>;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                               </span>Fx=<span style="color: #1716c9">M</span>->begin();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                      </span>} <span style="color: #910e66">else</span> Fx++;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">           </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(145, 14, 102); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">            </span></span>return<span style="color: #000000"> </span>true<span style="color: #000000">;</span></div></div><div><br></div><div>But I still have a bug:</div><div><br></div><div><div>opt(63981) malloc: *** error for object 0x7ff1394050a0: pointer being freed was not allocated</div><div>*** set a breakpoint in malloc_error_break to debug</div><div>0  libLLVM-3.0.dylib 0x00000001082d7605 _ZL15PrintStackTracePv + 53</div><div>1  libLLVM-3.0.dylib 0x00000001082d7c6c _ZL13SignalHandleri + 364</div><div>2  libsystem_c.dylib 0x00007fff9152dcfa _sigtramp + 26</div><div>3  libsystem_c.dylib 0x00007fff66d6a878 _sigtramp + 18446744072996768664</div><div>4  libsystem_c.dylib 0x00007fff9152b84c free + 389</div><div>5  libLLVM-3.0.dylib 0x00000001083536b0 __gnu_cxx::new_allocator<std::pair<llvm::WeakVH, llvm::CallGraphNode*> >::deallocate(std::pair<llvm::WeakVH, llvm::CallGraphNode*>*, unsigned long) + 32</div><div>6  libLLVM-3.0.dylib 0x000000010835360e std::_Vector_base<std::pair<llvm::WeakVH, llvm::CallGraphNode*>, std::allocator<std::pair<llvm::WeakVH, llvm::CallGraphNode*> > >::_M_deallocate(std::pair<llvm::WeakVH, llvm::CallGraphNode*>*, unsigned long) + 62</div><div>7  libLLVM-3.0.dylib 0x00000001083535bd std::_Vector_base<std::pair<llvm::WeakVH, llvm::CallGraphNode*>, std::allocator<std::pair<llvm::WeakVH, llvm::CallGraphNode*> > >::~_Vector_base() + 45</div><div>8  libLLVM-3.0.dylib 0x0000000108353509 std::vector<std::pair<llvm::WeakVH, llvm::CallGraphNode*>, std::allocator<std::pair<llvm::WeakVH, llvm::CallGraphNode*> > >::~vector() + 105</div><div>9  libLLVM-3.0.dylib 0x0000000108353495 std::vector<std::pair<llvm::WeakVH, llvm::CallGraphNode*>, std::allocator<std::pair<llvm::WeakVH, llvm::CallGraphNode*> > >::~vector() + 21</div><div>10 libLLVM-3.0.dylib 0x000000010852be3e llvm::CallGraphNode::~CallGraphNode() + 110</div><div>11 libLLVM-3.0.dylib 0x0000000108529d55 llvm::CallGraphNode::~CallGraphNode() + 21</div><div>12 libLLVM-3.0.dylib 0x0000000108528468 llvm::CallGraph::destroy() + 264</div><div>13 libLLVM-3.0.dylib 0x00000001085295f8 (anonymous namespace)::BasicCallGraph::destroy() + 120</div><div>14 libLLVM-3.0.dylib 0x0000000108529379 (anonymous namespace)::BasicCallGraph::releaseMemory() + 25</div><div>15 libLLVM-3.0.dylib 0x0000000107bf5d93 llvm::PMDataManager::freePass(llvm::Pass*, llvm::StringRef, llvm::PassDebuggingString) + 179</div><div>16 libLLVM-3.0.dylib 0x0000000107bf5c89 llvm::PMDataManager::removeDeadPasses(llvm::Pass*, llvm::StringRef, llvm::PassDebuggingString) + 505</div><div>17 libLLVM-3.0.dylib 0x0000000107bf8ee8 llvm::MPPassManager::runOnModule(llvm::Module&) + 1016</div><div>18 libLLVM-3.0.dylib 0x0000000107bf949c llvm::PassManagerImpl::run(llvm::Module&) + 172</div><div>19 libLLVM-3.0.dylib 0x0000000107bf997d llvm::PassManager::run(llvm::Module&) + 29</div><div>20 opt               0x000000010717f057 main + 6903</div><div>21 opt               0x000000010716d7b4 start + 52</div><div>22 opt               0x0000000000000007 start + 18446744069295646855</div></div><div><br></div><div><br></div><br><div apple-content-edited="true">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Yours sincerely,</div><div>Kadysev Mikhail</div></div></div>
</div>

<br><div><div>22.04.2012, Χ 23:30, Nick Lewycky ΞΑΠΙΣΑΜ(Α):</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>νΙΘΑΙΜ wrote:<br><blockquote type="cite">It is ModulePass with AnalysisUsage of CallGraph<br></blockquote><br>Ah, then you'll need to update the CallGraph first. Use "CG.removeFunctionFromModule(F);" before deleting it.<br><br>Nick<br><br><blockquote type="cite">Yours sincerely,<br></blockquote><blockquote type="cite">Kadysev Mikhail<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">22.04.2012, Χ 5:20, Nick Lewycky ΞΑΠΙΣΑΜ(Α):<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">νΙΘΑΙΜ wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Thanks, but I replaceAllUsesWith() - works well, but I still get bug in<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">eraseFromParent():<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">While deleting: i32 (%class.B*, i32)* %_ZN1B1xEi<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">An asserting value handle still pointed to this value!<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">UNREACHABLE executed at<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">/Users/neonomaly/LLVM/LLVM/lib/VMCore/Value.cpp:561!<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">The replaceAllUsesWith + eraseFromParent pattern remains correct, but<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">there's more to the story than the parts we've focused on. This error<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">means that there's some other code that is holding a pointer to the<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">function you tried to delete, but is using AssertingVH to do so, so as<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">to catch errors exactly like this producing a dangling pointer.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">The error message doesn't tell us who owns the AssertingVH (indeed,<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">the asserting-vh doesn't know, much like a pointer doesn't know who<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">owns it).<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">So, under what circumstance are you doing this deletion? Is it inside<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">a FunctionPass, or another kind of Pass? Are you using AssertingVH's<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">or calling other code that is? Such as ValueMap's, or some llvm<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">analysis pass which stores an AssertingVH?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Nick<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Yours sincerely,<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Kadysev Mikhail<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">21.04.2012, Χ 23:45, Nick Lewycky ΞΑΠΙΣΑΜ(Α):<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">νΙΘΑΙΜ wrote:<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">How correctly remove function from module?<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">For example:<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">int f1(int x) {<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">...<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">a = f2(smth);<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">...<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">}<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">int f2 (int y) {<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">...<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">b = f1(smth);<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">...<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">}<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">I need delete from module both f1 and f2. They haven't uses in other<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">part of module, but I can't delete them with eraseFromParent, because<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">they are use each other.<br></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Call X->replaceAllUsesWith(UndefValue::get(X->getType)) before calling<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">X->eraseFromParent().<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Nick<br></blockquote></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">_______________________________________________<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">LLVM Developers mailing list<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <<a href="mailto:LLVMdev@cs.uiuc.edu">mailto:LLVMdev@cs.uiuc.edu</a>> <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">LLVM Developers mailing list<br></blockquote><blockquote type="cite"><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br></blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote><br></div></blockquote></div><br></body></html>