[clang] [clang] LazyOffsetPtr: Use native pointer width (PR #111995)
Jessica Clarke via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 18 08:36:03 PDT 2024
jrtc27 wrote:
> > How about:
> > [...]
>
> Yeah, I think that fixes it. For me that looks a lot less simple than using a union, but it is nice to have only a single implementation. I'd be fine with going in that direction.
>
> For CHERI, can we assume that the least-significant byte of the pointer representation is even when the alignment of the type is > 1?
The integer address portion of the capability has the same representation, so will be even. On all little-endian CHERI platforms that exist today this is laid out in memory as you would expect, i.e. with the first byte being the LSB of the address and the last byte being the MSB of the metadata. Big-endian CHERI did historically exist and was a bit weird for various reasons, but will hopefully(?) never return. If it does, whoever wants to tackle that beast can port this code if it's no longer true there by fiddling with the offset calculations. But yes, the short answer is that the code as written should work on Morello and CHERI-RISC-V.
> > The std::launder may be unnecessary
>
> Formally I think it's correct and necessary for the pointer and integer case because an array element and an object for which the array provides storage are not pointer-interconvertible, but it's incorrect for the `unsigned char` case because there's no in-lifetime `unsigned char` object at the provided address.
I'll defer to your expert opinion for what exactly to do here. If the launder is needed for the other types but not GetLSB the obvious fix is to just inline a simple specialisation of As, assuming direct access to `Data` is still permitted despite there being no in-lifetime `unsigned char`.
https://github.com/llvm/llvm-project/pull/111995
More information about the cfe-commits
mailing list