/// hasAddressTaken - returns true if there are any uses of this basic block
/// other than direct branches, switches, etc. to it.
bool hasAddressTaken() const { return SubclassData != 0; }
+
+ /// removeDeadBlockAddress - If there is a blockaddress node for this basic
+ /// block, try to remove it and any dead constant users of it.
+ void removeDeadBlockAddress();
private:
/// AdjustBlockAddressRefCount - BasicBlock stores the number of BlockAddress
/// objects using it. This is almost always 0, sometimes one, possibly but
}
}
+/// removeDeadBlockAddress - If there is a blockaddress node for this basic
+/// block, try to remove it and any dead constant users of it.
+void BasicBlock::removeDeadBlockAddress() {
+ if (!hasAddressTaken()) return;
+ removeDeadUsersOfConstant(BlockAddress::get(this));
+}
+
+
/// Override destroyConstant to make sure it doesn't get called on
/// GlobalValue's because they shouldn't be treated like other constants.
void GlobalValue::destroyConstant() {
BasicBlock *Entry = &F.getEntryBlock();
Assert1(pred_begin(Entry) == pred_end(Entry),
"Entry block to function must not have predecessors!", Entry);
- Assert1(!Entry->hasAddressTaken(),
- "blockaddress may not be used with the entry block!", Entry);
+
+ // The address of the entry block cannot be taken, unless it is dead.
+ if (Entry->hasAddressTaken()) {
+ Entry->removeDeadBlockAddress();
+ Assert1(!Entry->hasAddressTaken(),
+ "blockaddress may not be used with the entry block!", Entry);
+ }
}
// If this function is actually an intrinsic, verify that it is only used in