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

            Bug ID: 128644
           Summary: [14/15/16/17 Regression] wrong code at -O2: modref
                    keeps stale "not returned" flags after ipa-cp; find()
                    == last folded to false since r12-5383
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffchen006 at gmail dot com
  Target Milestone: ---

int printf(const char *, ...);
static char *find(char *f, char *l, int k) {
  for (; f != l; ++f) {
    int c = *f;
    if (c == k || c == k + 1 || c == k * 3 || c == k - 7 ||
        c == k * 5 + 2 || c == k / 3 || c == (k ^ 5) || c == k * 7 - 1)
      return f;
  }
  return f;
}
int main(void) {
  char x[2] = {0};
  char *r = find(x, x + 1, 1000), *s = find(x, x + 2, 1000);
  printf("%d %d\n", r == x + 1, s == x + 2);
}

$ gcc -O0 t.c && ./a.out
1 1
$ gcc -O2 t.c && ./a.out
0 0

Expected: 1 1. No char matches 1000, so find returns l: both compares are true.
The long condition only stops inlining. libstdc++ 25_algorithms/find/bytes.cc
also fails with -O2 -fno-inline.

Suspected cause: ipa-modref analyze_parms ORs the stale IPA EAF flags
(not_returned) into the late summary of the ipa-cp clone (first bad
22c242342e3, 2021).

Avoided by: -fno-ipa-modref, -fno-tree-pta, -fno-ipa-cp.

Known to fail: 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0, 17.0.

Known to work: 7.5.0, 8.5.0, 10.5.0, 11.4.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 ipa/128644] New: [14/15/16/... jeffchen006 at gmail dot com via Gcc-bugs

Reply via email to