On Fri, 1 May 2020, Segher Boessenkool wrote: > On Mon, Apr 27, 2020 at 05:01:34PM -0500, will schmidt wrote: > > On Mon, 2020-04-27 at 15:53 -0400, Michael Meissner via Gcc-patches wrote: > > > +unsigned long > > > +load_us_offset1 (unsigned char *p) > > > +{ > > > + return *(unsigned short *)(p + 1); /* should generate LHZ. */ > > > +} > > This violates aliasing rules (without -fno-strict-aliasing), unless p > points to some "short" object -- in which case it has alignment 2 > already!
Ackchyually... that'd be 'unless p+1 points to some "short" object'. You're allowed to do weird things passing char pointers around (at least), as long as you point to the right-type object (the one used when it was assigned) when you dereference it. Though, I don't know if the same goes if p was something other than a "char *" or "unsigned char *". > So this testcase needs -fno-strict-aliasing, but also, you need to make > sure GCC does not assume alignment 2 (after the cast) already. There > are attributes for this. FWIW, if it needs -fno-strict-aliasing it's for some other reason than the above (we don't see the assigner in the test). brgds, H-P