A question about the BasicBlock::hasAddressTaken() implementation.

Hi Fellows,

BasicBlock::hasAddressTaken has the following implementation:

bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }

and then, in llvm/IR/Value.h, we have

unsigned short getSubclassDataFromValue() const { return SubclassData; }

But it’s not clear to me at all, how is (SubclassData != 0) equivalent to the basic block has its address taken? What’s the logic behind all these? Thanks so much.

Best Regards,
Paul

Hi Paul,

               unsigned short getSubclassDataFromValue() const { return
SubclassData; }

     But it's not clear to me at all, how is (SubclassData != 0) equivalent
to the basic block has its address taken? What's the logic behind all these?

That field in Value is there as a convenience for anything that
inherits from it to use to store a few bits of information. For
example, Atomic instructions store what ordering they've been given
there; I think arithmetic instructions use it for the wrapping
behaviour flags.

BasicBlock appears to use it as a reference count: whenever a
BasicBlockAddress is created, that value gets incremented by a call to
AdjustBlockAddressRefCount. So assuming all BasicBlockAddresses that
have been created are actually still in use, it should be accurate.
Just don't let them leak, I suppose!

Cheers.

Tim.