On Wed, Apr 22, 2020 at 11:41 PM Eric Botcazou <botca...@adacore.com> wrote: > > > What if we had this: > > uint32_t u = 0x12345678; > > upal_u32be_t tempb; > > memcpy (&tempb, &u, sizeof(uint32_t)); > > uint32_t bu = tempb.val; > > > > Is that valid? We still run into the wrong code with the above case. > > memcpy here should be considered a byte-by-byte copy and therefor > > should not have any type punning except for to bytes. > > The usual trick of people doing type punning and pretending they don't. ;-) > No, this cannot work as-is, although it's probably fixable by blocking the > propagation through the memcpy in case the scalar order is flipped, unlike the > previous example.
Yes the following is a decent workaround: upal_u32be_t tempb; memcpy (&tempb, &u, sizeof(uint32_t)); asm("":"+m"(tempb)); uint32_t bu = tempb.val; But I wish this customer would not do this but they want it for some reason. Thanks, Andrew Pinski > > -- > Eric Botcazou