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:
for(Module::iterator F= M.begin(), E = M.end(); F != E; ++F) // iterating over functions in a module
{
std::string function_name = F->getName();
if((std::find(calledFunctions.begin(), calledFunctions.end(), function_name) != calledFunctions.end())
&& function_name != current_function )
{
F->replaceAllUsesWith(UndefValue::get(F->getType()));
F->removeFromParent();
}
}
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)
Can someone please tell me if my approach is right? As of now, I'm getting a segmentation fault.