https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98502
Bug ID: 98502 Summary: Optimised memcpy breaks __scalar_storage_order__ Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: noring at nocrew dot org Target Milestone: --- Compiling with -O1 or greater breaks __scalar_storage_order__ with memcpy. The expected output of the test program below (sso.c) is "1234" but "3412" is produced with compiler optimisations: % gcc -Wall -o sso sso.c && ./sso 1234 % gcc -Wall -O1 -o sso sso.c && ./sso 3412 sso.c: #include <stdint.h> #include <stdio.h> #include <string.h> int main() { const uint8_t b[] = { 0x12, 0x34 }; struct __attribute__(( __scalar_storage_order__("big-endian") )) { uint16_t word; } s; memcpy(&s, b, sizeof(s)); printf("%04x\n", s.word); }