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

            Bug ID: 128469
           Summary: wrong code at -O1: modref drops a store in a nested
                    function that exits by non-local goto since r12-5126
           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: ---
            Target: x86_64-pc-linux-gnu

int printf(const char *, ...);

void test(int *p)
{
  {
    __label__ out;
    void nf(void) { *p = 0; goto out; }
    nf();
  out:;
  }
}

int main(void)
{
  int i = 1;
  test(&i);
  printf("%d\n", i);
  return 0;
}

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

-O1, -O2, -O3 all fail.

Expected: 0. nf stores 0 through p and then jumps to out, so i is 0.

modref marks nf "looping pure" because its only exit is the non-local goto, and
the store is dropped.

Avoided by: -fno-ipa-modref, -fno-ipa-pure-const.
Bisected to r12-5126-g992644c3511.
Correct on 8.5.0, 10.5.0.
Wrong on 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0, trunk.
-O0 -fsanitize=undefined,address is clean.

gcc version 17.0.0 20261029 (experimental), r17-5747-g85867b0c935,
x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release

Reply via email to