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

            Bug ID: 121020
           Summary: [16 regression] genrecog miscompiled
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: build, wrong-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

Originally reported by toralf downstream in Gentoo at
https://bugs.gentoo.org/959698 then by negril who gave me enough to reproduce
it.

genrecog is miscompiled and breaks in vec; vec has a tonne of checking asserts
so it makes sense that checking avoids it.

On trunk, I can reproduce with just:
```
$ mkdir ~/bugs/gcc && cd ~/bugs/gcc && ~/git/gcc/configure
--enable-checking=release
$ make -j$(nproc) -l$(nproc)
$ build/genrecog /home/sam/git/gcc/gcc/common.md
/home/sam/git/gcc/gcc/config/i386/i386.md insn-conditions.md -Hinsn-recog.h
-Otmp-recog-1.cc -Otmp-recog-2.cc -Otmp-recog-3.cc -Otmp-recog-4.cc
-Otmp-recog-5.cc -Otmp-recog-6.cc -Otmp-recog-7.cc -Otmp-recog-8.cc
-Otmp-recog-9.cc -Otmp-recog-10.cc
-Hinsn-recog.h
-Otmp-recog-1.cc
-Otmp-recog-2.cc
-Otmp-recog-3.cc
-Otmp-recog-4.cc
-Otmp-recog-5.cc
-Otmp-recog-6.cc
-Otmp-recog-7.cc
-Otmp-recog-8.cc
-Otmp-recog-9.cc
-Otmp-recog-10.cc
Segmentation fault         (core dumped) build/genrecog
/home/sam/git/gcc/gcc/common.md /home/sam/git/gcc/gcc/config/i386/i386.md
insn-conditions.md -Hinsn-recog.h -Otmp-recog-1.cc -Otmp-recog-2.cc
-Otmp-recog-3.cc -Otmp-recog-4.cc -Otmp-recog-5.cc -Otmp-recog-6.cc
-Otmp-recog-7.cc -Otmp-recog-8.cc -Otmp-recog-9.cc -Otmp-recog-10.cc
```

```
Program received signal SIGSEGV, Segmentation fault.
operator== (a=..., b=...) at /home/sam/git/gcc/gcc/vec.h:909
909     vec<T, A, vl_embed>::operator[] (unsigned ix)
(gdb) bt
#0  operator== (a=..., b=...) at /home/sam/git/gcc/gcc/vec.h:909
#1  operator!= (a=..., b=...) at /home/sam/git/gcc/gcc/genrecog.cc:1496
#2  common_test_p (d=<optimized out>, common=<optimized out>,
where=0x7fffffffcfe0) at /home/sam/git/gcc/gcc/genrecog.cc:1758
#3  common_test_p (d=<optimized out>, common=<optimized out>,
where=0x7fffffffcfe0) at /home/sam/git/gcc/gcc/genrecog.cc:1748
#4  0x00005555555625a3 in find_common_test (outer=0x55555ac0f8b0,
with_position_p=false, pos=0x0, worthwhile_single_p=<optimized out>,
kc=<optimized out>, where=0x7fffffffcfe0)
    at /home/sam/git/gcc/gcc/genrecog.cc:1906
#5  cse_tests (pos=<optimized out>, kc=kc@entry=0x7fffffffd360, s=<optimized
out>) at /home/sam/git/gcc/gcc/genrecog.cc:1964
#6  0x0000555555562284 in cse_tests (pos=<optimized out>,
kc=kc@entry=0x7fffffffd360, s=<optimized out>) at
/home/sam/git/gcc/gcc/genrecog.cc:2021
#7  0x0000555555562284 in cse_tests (pos=pos@entry=0x5555555fa980 <root_pos>,
kc=kc@entry=0x7fffffffd360, s=<optimized out>) at
/home/sam/git/gcc/gcc/genrecog.cc:2021
#8  0x0000555555568c43 in optimize_subroutine_group (type=0x5555555d1901
"recog", root=0x7fffffffd480) at /home/sam/git/gcc/gcc/genrecog.cc:2218
#9  0x0000555555558194 in main (argc=<optimized out>, argv=<optimized out>) at
/home/sam/git/gcc/gcc/genrecog.cc:5501
```

```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/16/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-16.0.9999/work/gcc-16.0.9999/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/16
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/16/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/16/include/g++-v16
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/16/python
--enable-libphobos --enable-objc-gc
--enable-languages=c,c++,d,objc,obj-c++,fortran,ada,cobol,m2,rust
--enable-obsolete --enable-secureplt --disable-werror --with-system-zlib
--enable-nls --without-included-gettext --disable-libunwind-exceptions
--enable-checking=yes,extra,rtl --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo Hardened 16.0.9999 p, commit
9dd46ee2eb01d30892f1c6db1599e82a9c6e8b04' --with-gcc-major-version-only
--enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point
--enable-targets=all --enable-offload-defaulted
--enable-offload-targets=nvptx-none --enable-libgomp --disable-libssp
--enable-libada --disable-cet --disable-systemtap --enable-valgrind-annotations
--disable-vtable-verify --disable-libvtv --with-zstd --with-isl
--disable-isl-version-check --enable-default-pie --enable-host-pie
--enable-host-bind-now --enable-default-ssp --disable-fixincludes
--with-gxx-libcxx-include-dir=/usr/include/c++/v1 --enable-linker-build-id
--with-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20250709 (experimental)
a09b415b87cd98e3a4f3e197ad4e9e67a335c1d4 (Gentoo Hardened 16.0.9999 p, commit
9dd46ee2eb01d30892f1c6db1599e82a9c6e8b04)
```

Reply via email to