Reland "[llvm][ADT] Refactor PointerUnion to use PunnedPointer. NFC." (#188242)
This reverts commit 040b7e0a1deb and re-lands the PointerUnion
refactoring from #187950, with a fix for the 32-bit crash.
The bug was in doCast: it masked with
PointerLikeTypeTraits<To>::NumLowBitsAvailable to strip tag bits, but
the old PointerIntPair-based code masked with minLowBitsAvailable() (the
minimum across all union members). When a member type's PLTT over-claims
spare low bits, the new mask was too aggressive and cleared bits
belonging to a nested PointerUnion's tag.
Concretely, on 32-bit systems, Redeclarable::DeclLink nests
LazyGenerationalUpdatePtr (LGUP) whose PLTT claims 2 spare bits (Decl*
has alignas(8) = 3 bits, minus 1). But LGUP's inner PointerUnion<Decl*,
LazyData*> only has 1 spare bit on 32-bit (alignof(LazyData) = 4 gives
LazyData* only 2 low bits, tagShift = 1). Extracting LGUP from the outer
PointerUnion cleared bit 1 (the inner PU's type tag), corrupting the
discriminator and breaking redeclaration chains.
Added new unit tests that cover this scenario, but we will want to fix
the clang side too.
Issue: #188269
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>