From 7d83ebcadd725d050cc58962e9b7c4312d676e7f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 31 Oct 2009 20:08:37 +0000 Subject: Make blockaddress(@func, null) be valid, and make 'deleting a basic block with a blockaddress still referring to it' replace the invalid blockaddress with a new blockaddress(@func, null) instead of a inttoptr(1). This changes the bitcode encoding format, and still needs codegen support (this should produce a non-zero value, referring to the entry block of the function would also be quite reasonable). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85678 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/AsmWriter.cpp | 5 ++++- lib/VMCore/BasicBlock.cpp | 8 +++----- lib/VMCore/Constants.cpp | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/VMCore') diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 9a803a1..df1d19b 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1065,7 +1065,10 @@ static void WriteConstantInt(raw_ostream &Out, const Constant *CV, Out << "blockaddress("; WriteAsOperandInternal(Out, BA->getFunction(), &TypePrinter, Machine); Out << ", "; - WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine); + if (BA->getBasicBlock()) + WriteAsOperandInternal(Out, BA->getBasicBlock(), &TypePrinter, Machine); + else + Out << "null"; Out << ")"; return; } diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 23d0557..c609ef8 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -63,15 +63,13 @@ BasicBlock::~BasicBlock() { // hanging off the block, or an undefined use of the block (source code // expecting the address of a label to keep the block alive even though there // is no indirect branch). Handle these cases by zapping the BlockAddress - // nodes. There are no other possible uses at this point. + // nodes, replacing them with BlockAddress(F, NULL). There are no other + // possible uses at this point. if (hasAddressTaken()) { assert(!use_empty() && "There should be at least one blockaddress!"); - Constant *Replacement = - ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1); while (!use_empty()) { BlockAddress *BA = cast(use_back()); - BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement, - BA->getType())); + BA->replaceAllUsesWith(BlockAddress::get(BA->getFunction(), 0)); BA->destroyConstant(); } } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 2d3d71b..e0adf9d 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1045,7 +1045,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB) &Op<0>(), 2) { Op<0>() = F; Op<1>() = BB; - BB->AdjustBlockAddressRefCount(1); + if (BB) BB->AdjustBlockAddressRefCount(1); } @@ -1054,7 +1054,8 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB) void BlockAddress::destroyConstant() { getFunction()->getType()->getContext().pImpl ->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock())); - getBasicBlock()->AdjustBlockAddressRefCount(-1); + if (BasicBlock *BB = getBasicBlock()) + BB->AdjustBlockAddressRefCount(-1); destroyConstantImpl(); } -- cgit v1.1