[PATCH] Bug 20788 - bugpoint does not respect the "Alias must point to a definition"
Nick Johnson
Nicholas.Paul.Johnson at deshawresearch.com
Wed May 6 08:06:11 PDT 2015
Fix bug 20788.
GlobalAliases may reference function definitions, but not function declarations.
bugpoint would sometimes create invalid IR by deleting a function's body (thus mutating a function definition into a declaration) without first 'fixing' any GlobalAliases that reference that function definition.
This patch iteratively prevents that issue. Before deleting a function's body, it scans the module for GlobalAliases which reference that function. When found, it eliminates them using replaceAllUsesWith.
http://reviews.llvm.org/D9529
Files:
tools/bugpoint/ExtractFunction.cpp
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<GlobalAlias*,1> 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(); i<N; ++i) {
+ aliases[i]->replaceAllUsesWith( 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!");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9529.25046.patch
Type: text/x-patch
Size: 1142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150506/2f6ec6b1/attachment.bin>
More information about the llvm-commits
mailing list