On Wed, Jul 30, 2025 at 10:17:42AM GMT, Jakub Jelinek wrote:
> On Wed, Jul 30, 2025 at 10:16:06AM +0200, Jakub Jelinek wrote:
> > Or maybe better
> >   _BitInt(PROMOTED_SIZE (x) * __CHAR_BIT__) __x;
> >   int __y = S (x);
> >   do_copy (&__x, &(x), sizeof (__x));
> >   if (__y < PROMOTED_SIZE (x) * __CHAR_BIT__)
> >     {
> >       int __neg = __x < 0;
> >       __x >>= PROMOTED_SIZE (x) * __CHAR_BIT__ - __y;
> 
> Obviously __x >>= __y;
> We want to shift away all the normal bits and keep just the padding bits
> which aren't padding in the promoted type.
> 
> >       if (__x != (__neg ? (typeof (__x)) -1 : (__typeof (__x)) 0))
> >     __builtin_abort ();
> >     }
> > and just no __neg and if (__x) in the unsigned case?
> > The intent is not to invoke any UB, just have the memcpy hidden
> > from the optimizers.
> 
>       Jakub

I'm not sure if this is correct, but isn't accessing __x in its own type
after do_copy already an undefined behavior? 

N3301 J.2 (34)
> An object has its stored value accessed other than by an lvalue of
> an allowable type (6.5.1).

where "allowable type" refers to some variant of a compatible type,
and "_BitInt(PROMOTED_SIZE (x) * __CHAR_BIT__)" is not an allowable
type to access the object of (x).

Reply via email to