summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2013-06-13 19:51:17 +0000
committerDerek Schuff <dschuff@google.com>2013-06-13 19:51:17 +0000
commitc06e5cf2e3724762a6c9830a00395736ec07d81a (patch)
tree096aea2893f2d7ea5541aa6f27b5d19d16acd54f /lib/Transforms
parent6585b388cb7bfc623adb9e4dd910423f838e5d96 (diff)
downloadllvm-c06e5cf2e3724762a6c9830a00395736ec07d81a.tar.gz
llvm-c06e5cf2e3724762a6c9830a00395736ec07d81a.tar.bz2
llvm-c06e5cf2e3724762a6c9830a00395736ec07d81a.tar.xz
Fix DeleteDeadVarargs not to crash on functions referenced by BlockAddresses
This pass was assuming that if hasAddressTaken() returns false for a function, the function's only uses are call sites. That's not true because there can be references by BlockAddresses too. Fix the pass to handle this case. Fix BlockAddress::replaceUsesOfWithOnConstant() to allow a function's type to be changed by RAUW'ing the function with a bitcast of the recreated function. Patch by Mark Seaborn. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 3fdb5f0e58..70d03178cb 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -263,8 +263,10 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
// to pass in a smaller number of arguments into the new function.
//
std::vector<Value*> Args;
- while (!Fn.use_empty()) {
- CallSite CS(Fn.use_back());
+ for (Value::use_iterator I = Fn.use_begin(), E = Fn.use_end(); I != E; ) {
+ CallSite CS(*I++);
+ if (!CS)
+ continue;
Instruction *Call = CS.getInstruction();
// Pass all the same arguments.
@@ -330,6 +332,11 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
if (DI != FunctionDIs.end())
DI->second.replaceFunction(NF);
+ // Fix up any BlockAddresses that refer to the function.
+ Fn.replaceAllUsesWith(ConstantExpr::getBitCast(NF, Fn.getType()));
+ // Delete the bitcast that we just created, so that NF does not
+ // appear to be address-taken.
+ NF->removeDeadConstantUsers();
// Finally, nuke the old function.
Fn.eraseFromParent();
return true;