diff options
| author | Chris Lattner <sabre@nondot.org> | 2011-02-18 04:43:06 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2011-02-18 04:43:06 +0000 |
| commit | 1a924e770ad01b524d7477473a1ded63c90242aa (patch) | |
| tree | 90fa3eaa6a10abfc4c8b04086fb1f8a836b9040e /llvm/lib | |
| parent | 8488640da7f65d06703b53eddf1f36ba8f216072 (diff) | |
| download | bcm5719-llvm-1a924e770ad01b524d7477473a1ded63c90242aa.tar.gz bcm5719-llvm-1a924e770ad01b524d7477473a1ded63c90242aa.zip | |
prevent jump threading from merging blocks when their address is
taken (and used!). This prevents merging the blocks (invalidating
the block addresses) in a case like this:
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
void foo() {
printf("%p\n", _THIS_IP_);
printf("%p\n", _THIS_IP_);
printf("%p\n", _THIS_IP_);
}
which fixes PR4151.
llvm-svn: 125829
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 3d218a6585a..90094a8da25 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -606,6 +606,16 @@ static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB) { return MinSucc; } +static bool hasAddressTakenAndUsed(BasicBlock *BB) { + if (!BB->hasAddressTaken()) return false; + + // If the block has its address taken, it may be a tree of dead constants + // hanging off of it. These shouldn't keep the block alive. + BlockAddress *BA = BlockAddress::get(BB); + BA->removeDeadConstantUsers(); + return !BA->use_empty(); +} + /// ProcessBlock - If there are any predecessors whose control can be threaded /// through to a successor, transform them now. bool JumpThreading::ProcessBlock(BasicBlock *BB) { @@ -621,7 +631,7 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) { // predecessors of our predecessor block. if (BasicBlock *SinglePred = BB->getSinglePredecessor()) { if (SinglePred->getTerminator()->getNumSuccessors() == 1 && - SinglePred != BB) { + SinglePred != BB && !hasAddressTakenAndUsed(BB)) { // If SinglePred was a loop header, BB becomes one. if (LoopHeaders.erase(SinglePred)) LoopHeaders.insert(BB); |

