[llvm-commits] [llvm] r64844 - in /llvm/trunk: lib/Transforms/IPO/GlobalDCE.cpp test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll
Duncan Sands
baldrick at free.fr
Tue Feb 17 15:05:27 PST 2009
Author: baldrick
Date: Tue Feb 17 17:05:26 2009
New Revision: 64844
URL: http://llvm.org/viewvc/llvm-project?rev=64844&view=rev
Log:
If an alias is dead and so is its aliasee, then globaldce would
crash because the alias would still be using the aliasee when the
aliasee was deleted.
Added:
llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp?rev=64844&r1=64843&r2=64844&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalDCE.cpp Tue Feb 17 17:05:26 2009
@@ -82,7 +82,7 @@
I != E; ++I) {
Changed |= RemoveUnusedGlobalValue(*I);
// Externally visible aliases are needed.
- if (!I->hasInternalLinkage() && !I->hasLinkOnceLinkage())
+ if (!I->hasLocalLinkage() && !I->hasLinkOnceLinkage())
GlobalIsNeeded(I);
}
@@ -107,6 +107,15 @@
I->deleteBody();
}
+ // The third pass drops targets of aliases which are dead...
+ std::vector<GlobalAlias*> DeadAliases;
+ for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;
+ ++I)
+ if (!AliveGlobals.count(I)) {
+ DeadAliases.push_back(I);
+ I->setAliasee(0);
+ }
+
if (!DeadFunctions.empty()) {
// Now that all interferences have been dropped, delete the actual objects
// themselves.
@@ -128,14 +137,13 @@
}
// Now delete any dead aliases.
- for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) {
- Module::alias_iterator J = I++;
- if (!AliveGlobals.count(J)) {
- RemoveUnusedGlobalValue(*J);
- M.getAliasList().erase(J);
- ++NumAliases;
- Changed = true;
+ if (!DeadAliases.empty()) {
+ for (unsigned i = 0, e = DeadAliases.size(); i != e; ++i) {
+ RemoveUnusedGlobalValue(*DeadAliases[i]);
+ M.getAliasList().erase(DeadAliases[i]);
}
+ NumAliases += DeadAliases.size();
+ Changed = true;
}
// Make sure that all memory is released
Added: llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll?rev=64844&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll (added)
+++ llvm/trunk/test/Transforms/GlobalDCE/2009-02-17-AliasUsesAliasee.ll Tue Feb 17 17:05:26 2009
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s | opt -globaldce
+
+ at A = alias internal void ()* @F
+define internal void @F() { ret void }
More information about the llvm-commits
mailing list