Index: tools/bugpoint/ExtractFunction.cpp =================================================================== --- tools/bugpoint/ExtractFunction.cpp +++ tools/bugpoint/ExtractFunction.cpp @@ -184,6 +184,26 @@ // blocks, making it external. // void llvm::DeleteFunctionBody(Function *F) { + // First, check whether a GlobalAlias references this declaration. + // GlobalAlias MAY NOT reference declarations. + for(;;) { + // 1. Find aliases + SmallVector aliases; + Module *M = F->getParent(); + for(Module::alias_iterator i=M->alias_begin(), E=M->alias_end(); i!=E; ++i) + if( i->getAliasee() == F ) + aliases.push_back(&*i); + if( aliases.empty() ) + break; + // 2. Resolve aliases + for(unsigned i=0, N=aliases.size(); ireplaceAllUsesWith( aliases[i]->getAliasee() ); + aliases[i]->eraseFromParent(); + } + // 3. Repeat until no more aliases found; there might + // be an alias to an alias... + } + // delete the body of the function... F->deleteBody(); assert(F->isDeclaration() && "This didn't make the function external!");