https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128645

            Bug ID: 128645
           Summary: [16/17 Regression] wrong code at -O3: partial PRE
                    gives a double load the value of an older long store
                    past a may-alias double store since r16-8128
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: alias, wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffchen006 at gmail dot com
  Target Milestone: ---

int printf(const char *, ...);
void *malloc(unsigned long);
long f(char *b, int o, int m, int k) {
  *(long *)b = 1;
  if (m)
    *(double *)(b + o) = 5;
  else
    *(long *)b = 2;
  if (k)
    return *(double *)b;
  return *(long *)b;
}
int o0 = 0, m0 = 1, k0 = 1;
long (*fp)(char *, int, int, int) = f;
int main(void) {
  printf("%ld\n", fp(malloc(8), o0, m0, k0));
}

$ gcc -O0 t.c && ./a.out
5
$ gcc -O3 t.c && ./a.out
0

Expected: 5. o = 0, m = k = 1: the double 5 is stored at b and read back as
double, so f returns 5. -O3 (and -O2 -ftree-partial-pre) reads the bits of long
1 as a double (0). 12.5-15.2 do not show it (hidden).

Suspected cause: partial PRE phi-translation of the double load goes past the
may-alias double store (first bad 3d6fd7ce6dc, 2020, PR93946; back in 16 via
5f1024922d3, 2026, PR122380).

Avoided by: -fno-tree-partial-pre, -fno-tree-pre, -fno-strict-aliasing.

Known to fail: 10.5.0, 11.4.0, 16.2.0, 17.0.

Known to work: 7.5.0, 8.5.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0.

-O0 -fsanitize=undefined,address is clean.

gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release
  • [Bug tree-optimization/128645] N... jeffchen006 at gmail dot com via Gcc-bugs

Reply via email to