[PATCH] Bug 20788 - bugpoint does not respect the "Alias must point to a definition"
Nick Johnson
Nicholas.Paul.Johnson at deshawresearch.com
Thu May 14 07:18:49 PDT 2015
@dberlin: your testcase demonstrates that a GlobalAlias may refer to any kind of ConstantExpr, whereas my previous patch incorrectly assumed that the aliasee must be an llvm::Function.
Consequently, the test on line 194 needs a ->stripPointerCasts(). My latest patch handles that testcase correctly.
@dberlin: you mentioned you have many test cases. Would you be so kind as to run this latest patch on them? Thanks,
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 definition.
+ // 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()->stripPointerCasts() == F)
+ aliases.push_back(&*I);
+ if (aliases.empty())
+ break;
+ // 2. Resolve aliases
+ for (unsigned i=0, e=aliases.size(); i<e; ++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.25771.patch
Type: text/x-patch
Size: 1161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150514/2d0edbf2/attachment.bin>
More information about the llvm-commits
mailing list