https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116316
Bug ID: 116316 Summary: incorrect code with -O2 Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: qinzhao at gcc dot gnu.org Target Milestone: --- the following testing case failed on both x86 and aarch64 with -O2, but passed with -O1: #include <stdio.h> struct annotated { int b; int c[]; } *array_annotated; int main(int argc, char *argv[]) { size_t __size = sizeof(struct annotated) + sizeof(*array_annotated->c) * 10; array_annotated = (struct annotated *) __builtin_malloc(__size); __builtin_memset(array_annotated, 0, __size); if (&(array_annotated->b)) *(size_t *)(&(array_annotated->b)) = 10; if (array_annotated->b != 10) __builtin_abort (); printf("pass\n"); return 0; } adding -fno-tree-fre -fno-tree-pre -fno-code-hoisting cures the issue [opc@qinzhao-aarch64-ol8 ~]$ ./Install/latest-d/bin/gcc t.c -O2 [opc@qinzhao-aarch64-ol8 ~]$ ./a.out Aborted (core dumped) [opc@qinzhao-aarch64-ol8 ~]$ ./Install/latest-d/bin/gcc t.c -O2 -fno-tree-fre -fno-tree-pre -fno-code-hoisting [opc@qinzhao-aarch64-ol8 ~]$ ./a.out pass