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

            Bug ID: 119968
           Summary: miscompliation at -O1 or higher
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urs at akk dot org
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu
             Build: x86_64-pc-linux-gnu

Created attachment 61215
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61215&action=edit
miscompiled with gcc-16 -O2

The reproducer needs to be linked against libpcre2 (-lpcre2-8).
It gives the correct result if compiled with -O0 and miscompiles with >= O1.

If the two pcre2_substring_get_byname_8() calls are swapped no miscompilation
happens. The oldest gcc I've tested and seen the miscompilation was
gcc-12 (Debian 12.2.0-14) (also x86_64-pc-linux-gnu; I did not test any other
archs), I didn't test older versions.

expected outout is y_ecrc: 17994587, y_epcrc: 17994587 with a return value of 0

for c in gcc-13 gcc-16 ; do $c --version | head -n 1 ; for i in $(seq 1 3) ; do
gcc -O$i -W -Wall -Wextra -g -o rege regex.c -lpcre2-8 ; ./rege ; echo $? ;
done ; done
gcc-13 (Debian 13.3.0-13) 13.3.0
y_ecrc: 17994587, y_epcrc: 17994587
0
y_ecrc: 17994587, y_epcrc: 0
1
y_ecrc: 17994587, y_epcrc: 0
1
gcc-16 (GCC) 16.0.0 20250427 (experimental)
y_ecrc: 17994587, y_epcrc: 17994587
0
y_ecrc: 17994587, y_epcrc: 0
1
y_ecrc: 17994587, y_epcrc: 0
1

gcc-16 is build from git @ f962f594e9006651379dafc9ef039be9654e6291
with configure \
 --program-suffix=-16 --with-gcc-major-version-only \
 --enable-languages=c,lto --enable-lto --disable-multilib \
 --enable-default-pie \
 --without-included-gettext --with-system-zlib \
 --with-tune=generic \
 --enable-libgdiagnostics --enable-host-shared

on x86_64-pc-linux-gnu with glibc-2.41

Reply via email to