[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 11:35:27 PDT 2015
@dberlin: I'm unable to recreate your crash. However, I have a hunch that it pertains to aliases to global variables, rather than aliases to functions.
The new patch (attached) eliminates aliases before calls to GV->setInitializer(nullptr).
http://reviews.llvm.org/D9529
Files:
tools/bugpoint/BugDriver.h
tools/bugpoint/CrashDebugger.cpp
tools/bugpoint/ExtractFunction.cpp
Index: tools/bugpoint/BugDriver.h
===================================================================
--- tools/bugpoint/BugDriver.h
+++ tools/bugpoint/BugDriver.h
@@ -321,6 +321,11 @@
///
void PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs);
+// DeleteGlobalInitializer - "Remove" the global variable by deleting its
+// initializer, making it external.
+//
+void DeleteGlobalInitializer(GlobalVariable *GV);
+
// DeleteFunctionBody - "Remove" the function by deleting all of it's basic
// blocks, making it external.
//
Index: tools/bugpoint/CrashDebugger.cpp
===================================================================
--- tools/bugpoint/CrashDebugger.cpp
+++ tools/bugpoint/CrashDebugger.cpp
@@ -158,7 +158,7 @@
for (Module::global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I)
if (I->hasInitializer() && !GVSet.count(I)) {
- I->setInitializer(nullptr);
+ DeleteGlobalInitializer(I);
I->setLinkage(GlobalValue::ExternalLinkage);
}
@@ -516,7 +516,7 @@
for (Module::global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I)
if (I->hasInitializer()) {
- I->setInitializer(nullptr);
+ DeleteGlobalInitializer(I);
I->setLinkage(GlobalValue::ExternalLinkage);
DeletedInit = true;
}
Index: tools/bugpoint/ExtractFunction.cpp
===================================================================
--- tools/bugpoint/ExtractFunction.cpp
+++ tools/bugpoint/ExtractFunction.cpp
@@ -179,11 +179,43 @@
return NewM;
}
+static void eliminateAliases(GlobalValue *GV) {
+ // First, check whether a GlobalAlias references this definition.
+ // GlobalAlias MAY NOT reference declarations.
+ for (;;) {
+ // 1. Find aliases
+ SmallVector<GlobalAlias*,1> aliases;
+ Module *M = GV->getParent();
+ for (Module::alias_iterator I=M->alias_begin(), E=M->alias_end(); I!=E; ++I)
+ if (I->getAliasee()->stripPointerCasts() == GV)
+ 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...
+ }
+}
+
+//
+// DeleteGlobalInitializer - "Remove" the global variable by deleting its initializer,
+// making it external.
+//
+void llvm::DeleteGlobalInitializer(GlobalVariable *GV) {
+ eliminateAliases(GV);
+ GV->setInitializer(nullptr);
+}
// DeleteFunctionBody - "Remove" the function by deleting all of its basic
// blocks, making it external.
//
void llvm::DeleteFunctionBody(Function *F) {
+ eliminateAliases(F);
+
// delete the body of the function...
F->deleteBody();
assert(F->isDeclaration() && "This didn't make the function external!");
@@ -325,10 +357,10 @@
<< "' and from test function '" << TestFn->getName() << "'.\n";
exit(1);
}
- I->setInitializer(nullptr); // Delete the initializer to make it external
+ DeleteGlobalInitializer(I); // Delete the initializer to make it external
} else {
// If we keep it in the safe module, then delete it in the test module
- GV->setInitializer(nullptr);
+ DeleteGlobalInitializer(GV);
}
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9529.25795.patch
Type: text/x-patch
Size: 3397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150514/4f037fd1/attachment.bin>
More information about the llvm-commits
mailing list