https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114046
Bug ID: 114046 Summary: Aarch64: Os,O1,02,O3 optimisations generates unaligned access in short members of structure Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: stephane at syena dot net Target Milestone: --- The issuer is reproduced with the following (simplified) code: struct test { short a; short b; short c; }; void function( struct test *p, int n ) { p->a = n; p->b = 0; p->c = 0; } # gcc -Os -S unaligned_store.c && cat unaligned_store.s .arch armv8-a .file "unaligned_store.c" .text .align 2 .global function .type function, %function function: strh w1, [x0] str wzr, [x0, 2] <<<<<<<<< Alignment fault ret .size function, .-function .ident "GCC: (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.1 20231009" The second instruction generates an unaligned 32-bits store at a 16-bits aligned address. I suspect that the optimizer detects that consecutive short members b and c are both set to zero and group them to generate a single long access but somehow fails to detect that the resulting access is not aligned.