[clang] Remove type-punning in LazyOffsetPtr. (PR #112806)

A. Wilcox via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 17 19:25:53 PDT 2024


awilfox wrote:

> This violates aliasing rules and doesn't work at all on big-endian 64-bit systems where the pointer is stored in the second four bytes of the uint64_t.

Your sizes aren't correct in the description here.  This issue occurs on big endian 32-bit systems, and the pointer is stored in the lower bits, which are lost because of using address-of when turning the 64-bit number into a pointer.  i.e. storing 0x12345678 yields:

```
|---------------------------|
| XXXX | XXXX | 1234 | 5678 |
|---------------------------|
```

If you just cast down to a `uintptr_t` (or such), you get the correct value.  But if you point to the *address of* this 64-bit value, and access a 32-bit value, you receive the `XXXX'XXXX` instead of `1234'5678`.

https://github.com/llvm/llvm-project/pull/112806


More information about the cfe-commits mailing list