title: llvm - delete a function from a file
body: <p>I have a file in which the main function calls three test functions, namely, test 1, test 2 and test 3. I want to make a pass that deletes each two of the functions one by one and returns the file that's calling only one of the three test functions. Right now, my pass is a ModulePass with this body:</p>
  
  <pre><code> for(Module::iterator F= M.begin(), E = M.end(); F != E; ++F) // iterating over functions in a module
      {
              std::string function_name = F-&gt;getName();   
              if((std::find(calledFunctions.begin(), calledFunctions.end(), function_name) != calledFunctions.end())
                      &amp;&amp; function_name != current_function ) 
              {
                  F-&gt;replaceAllUsesWith(UndefValue::get(F-&gt;getType()));
                  F-&gt;removeFromParent(); 
              }
      }
  </code></pre>
  
  <p>where called functions contain the functions you want gone (say, test 2 and test 3) and current_function is the one you want in the main function (test 1 in this case)</p>
  
  <p>Can someone please tell me if my approach is right? As of now, I'm getting a segmentation  fault. </p>