On Wed, Jul 30, 2025 at 11:28:11AM GMT, Jakub Jelinek wrote:
> On Wed, Jul 30, 2025 at 04:56:06PM +0800, Yang Yujie wrote:
> > 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).
> 
> It is copied using memcpy, so accessed using char type.
> That can copy also padding/trap etc. bits, but if the ABI say certain
> padding bits have some guaranteed state, at least by extension it should be
> ok to verify that.
> In your patch, it wasn't really testing anything about the padding bits
> unless it relies on the compiler not doing or doing some optimization (if it
> works at all).  By doing the shift, it really tests the content of those
> padding bits (and by do_copy being noipa that serves as an optimization
> barrier, so it will always test those bits, can't assume they are right
> or what exactly __x will contain).
> 
>       Jakub

So wouldn't it be simpler if I just change the comparison in my patch into
a memcmp?  This works regardless of how comparison is implemented.
(We all assume that expression (x) may have its address taken.)

Yujie

Reply via email to