public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/116316] New: incorrect code with -O2
@ 2024-08-09 18:42 qinzhao at gcc dot gnu.org
  2024-08-09 18:51 ` [Bug tree-optimization/116316] " pinskia at gcc dot gnu.org
  2024-08-09 19:15 ` qinzhao at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2024-08-09 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-09 19:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-09 18:42 [Bug tree-optimization/116316] New: incorrect code with -O2 qinzhao at gcc dot gnu.org
2024-08-09 18:51 ` [Bug tree-optimization/116316] " pinskia at gcc dot gnu.org
2024-08-09 19:15 ` qinzhao at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).