Is there a defined way to get the address of a BasicBlock as a value?
According to the language reference, any use outside of indirectbr and
comparison against null is undefined. There is some wording about
targets possibly allowing use in inline assembly. Is that really the
only option? Is there anything a pass can query to see if it is allowed
for a target? I don't see anything like that in TTI.
I found this hand-wavy post:
However, that seems to go against the language rules and could break at
any time. In particular, what happens if the BasicBlock is optimized
away (merged with another block, etc.)?
Taking a block's address is equivalent to taking the address of the label that starts it. When a block is marked as "address-taken" the label sticks around even after the block itself has been removed.
Checked the source---apparently blockaddress does get replaced with 1 when a block is deleted.
If you're trying to take the address of a BasicBlock at the IR level, you're probably not framing your problem correctly. If you're not using it in an indirectbr, it's basically an arbitrary address inside the current function, so you can't really do anything useful with it. You might want to consider if it's possible to express the semantics you want with an intrinsic.
(Of course, a MachineBasicBlock is a completely different story; various parts of code generation involve taking the address of a block.)