https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127600
Bug ID: 127600
Summary: wrong code at -O{2,3}
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
### Reproducer
#include <stdio.h>
int f (int *a, int n)
{
int last = -1;
int j = 1;
for (int i = 0; i < n; i++)
{
if (a[i])
last = j;
j = -j;
}
return last;
}
int
main (void)
{
int a[16] = { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
printf ("%d\n", f (a, 16));
return 0;
}
Stdout:
-O0/1/s: 1
-O2/3: -1
https://gcc.godbolt.org/z/dcKvjfP98