https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119016
Bug ID: 119016
Summary: [15 regression] svn miscompiled with -O2 -mavx
-fno-vect-cost-model
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: sjames at gcc dot gnu.org
Target Milestone: ---
```
#include <stdint.h>
#include <stddef.h>
__attribute__((noipa))
char *svn_eol__find_eol_start(char *buf,
size_t len) {
for (; len > sizeof(uintptr_t);
buf += sizeof(uintptr_t), len -= sizeof(uintptr_t)) {
uintptr_t chunk = *(const uintptr_t *)buf;
uintptr_t r_test = chunk ^ 0x0a0a0a0a0a0a0a0a;
uintptr_t n_test = chunk ^ 0x0d0d0d0d0d0d0d0d;
r_test |= (r_test & 0x7f7f7f7f7f7f7f7f) + 0x7f7f7f7f7f7f7f7f;
n_test |= (n_test & 0x7f7f7f7f7f7f7f7f) + 0x7f7f7f7f7f7f7f7f;
if ((r_test & n_test & 0x8080808080808080) != 0x8080808080808080)
break;
}
for (; len > 0; ++buf, --len) {
if (*buf == '\n' || *buf == '\r')
return buf;
}
return ((void *)0);
}
const char *svn_eol__detect_eol(char *buf, size_t len, char **eolp) {
char *eol;
eol = svn_eol__find_eol_start(buf, len);
if (eol) {
if (eolp)
*eolp = eol;
if (*eol == '\n')
return "\n";
++eol;
if (eol == buf + len || *eol != '\n')
return "\r";
return "\r\n";
}
return ((void *)0);
}
int main() {
size_t len;
char p[] = {0x2f, 0x2a, 0xa, 0x20, 0x20, 0x20, 0x62, 0x75, 0x67, 0x33, 0x33,
0x37, 0x39, 0x37, 0x32, 0x33, 0x2e, 0x63, 0xa, 0x2a, 0x2f, 0xa, 0xa, 0x23,
0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64,
0x65, 0x20, 0x3c, 0x74, 0x65, 0x73, 0x74, 0x66, 0x77, 0x6b, 0x2e, 0x68,
0x3e, 0xa, 0xa, 0x23, 0x69, 0x66, 0x20, 0x21, 0x64, 0x65, 0x66, 0x69, 0x6e,
0x65, 0x64, 0x28, 0x50, 0x4f,
0x52, 0x54, 0x5f, 0x48, 0x4f, 0x53, 0x54, 0x29, 0x20, 0x26, 0x26, 0x20,
0x21, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44,
0x43, 0x43, 0x5f, 0x68, 0x63,
0x30, 0x38, 0x29, 0x20, 0x26, 0x26, 0x20, 0x21, 0x64, 0x65, 0x66, 0x69,
0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44, 0x43, 0x43, 0x5f, 0x73, 0x30,
0x38, 0x29, 0x20, 0x26, 0x26,
0x20, 0x21, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f,
0x53, 0x44, 0x43, 0x43, 0x5f, 0x6d, 0x6f, 0x73, 0x36, 0x35, 0x30, 0x32, 0x29,
0x20, 0x26, 0x26, 0x20, 0x21,
0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44,
0x43, 0x43, 0x5f, 0x6d, 0x6f, 0x73, 0x36, 0x35, 0x63, 0x30, 0x32, 0x29, 0x20,
0x26, 0x26, 0x20, 0x21, 0x64,
0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44, 0x43,
0x43, 0x5f, 0x73, 0x6d, 0x38, 0x33, 0x29, 0x20, 0x26, 0x26, 0x20, 0x21, 0x64,
0x65, 0x66, 0x69, 0x6e, 0x65,
0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44, 0x43, 0x43, 0x5f, 0x73, 0x74, 0x6d,
0x38, 0x29, 0x20, 0x26, 0x26, 0x20, 0x21, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65,
0x64, 0x28, 0x5f, 0x5f, 0x53,
0x44, 0x43, 0x43, 0x5f, 0x74, 0x6c, 0x63, 0x73, 0x39, 0x30, 0x29, 0x20,
0x26, 0x26, 0x20, 0x21, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f,
0x5f, 0x53, 0x44, 0x43, 0x43,
0x5f, 0x70, 0x64, 0x6b, 0x31, 0x34, 0x29, 0x20, 0x26, 0x26, 0x20, 0x21,
0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44, 0x43,
0x43, 0x5f, 0x70, 0x64, 0x6b,
0x31, 0x35, 0x29, 0x20, 0x26, 0x26, 0x20, 0x21, 0x64, 0x65, 0x66, 0x69,
0x6e, 0x65, 0x64, 0x28, 0x5f, 0x5f, 0x53, 0x44, 0x43, 0x43, 0x5f, 0x66, 0x38,
0x29, 0xa, 0xa, 0x23, 0x64,
0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x55, 0x43, 0x48, 0x41, 0x52, 0x9,
0x75, 0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x68, 0x61, 0x72,
0xa, 0xa, 0x5f, 0x5f, 0x73, 0x66,
0x72, 0x20, 0x5f, 0x5f, 0x61, 0x74, 0x20, 0x30, 0x78, 0x66, 0x30, 0x20,
0x72, 0x47, 0x50, 0x49, 0x4f, 0x5f, 0x42, 0x5f, 0x4f, 0x75, 0x74, 0x70, 0x75,
0x74, 0x5f, 0x45, 0x6e, 0x61,
0x62, 0x6c, 0x65, 0x3b, 0xa, 0x5f, 0x5f, 0x73, 0x66, 0x72, 0x20, 0x5f,
0x5f, 0x61, 0x74, 0x20, 0x30, 0x78, 0x66, 0x31, 0x20, 0x72, 0x47, 0x50, 0x49,
0x4f, 0x5f, 0x42, 0x5f, 0x49,
0x6e, 0x70, 0x75, 0x74, 0x5f, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x3b,
0xa, 0x5f, 0x5f, 0x73, 0x66, 0x72, 0x20, 0x5f, 0x5f, 0x61, 0x74, 0x20, 0x30,
0x78, 0x66, 0x32, 0x20, 0x72,
0x47, 0x50, 0x49, 0x4f, 0x5f, 0x42, 0x3b, 0xa, 0xa, 0x55, 0x43, 0x48, 0x41,
0x52, 0x20, 0x5f, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x42, 0x5f, 0x42, 0x79,
0x5f, 0x42, 0x28, 0x55,
0x43, 0x48, 0x41, 0x52, 0x20, 0x69, 0x41, 0x6e, 0x64, 0x4d, 0x61, 0x73,
0x6b, 0x29, 0x9, 0x9, 0x2f, 0x2f, 0x20, 0x70, 0x75, 0x6c, 0x6c, 0x20, 0x6c,
0x6f, 0x77, 0xa, 0x7b, 0xa, 0x9,
0x55, 0x43, 0x48, 0x41, 0x52, 0x20, 0x69, 0x56, 0x61, 0x6c, 0x2c, 0x20,
0x69, 0x4f, 0x72, 0x4d, 0x61, 0x73, 0x6b, 0x3b, 0xa, 0xa, 0x9, 0x69, 0x4f,
0x72, 0x4d, 0x61, 0x73, 0x6b, 0x20,
0x3d, 0x20, 0x7e, 0x69, 0x41, 0x6e, 0x64, 0x4d, 0x61, 0x73, 0x6b, 0x3b,
0xa, 0x9, 0x72, 0x47, 0x50, 0x49, 0x4f, 0x5f, 0x42, 0x5f, 0x49, 0x6e, 0x70,
0x75, 0x74, 0x5f, 0x45, 0x6e,
0x61, 0x62, 0x6c, 0x65, 0x20, 0x26, 0x3d, 0x20, 0x69, 0x41, 0x6e, 0x64,
0x4d, 0x61, 0x73, 0x6b, 0x3b, 0xa, 0x9, 0x72, 0x47, 0x50, 0x49, 0x4f, 0x5f,
0x42, 0x5f, 0x4f, 0x75, 0x74,
0x70, 0x75, 0x74, 0x5f, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x7c,
0x3d, 0x20, 0x69, 0x4f, 0x72, 0x4d, 0x61, 0x73, 0x6b, 0x3b, 0x9, 0xa, 0x9,
0x72, 0x47, 0x50, 0x49, 0x4f, 0x5f,
0x42, 0x20, 0x7c, 0x3d, 0x20, 0x69, 0x4f, 0x72, 0x4d, 0x61, 0x73, 0x6b,
0x3b, 0xa, 0x9, 0x69, 0x56, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x72, 0x47, 0x50,
0x49, 0x4f, 0x5f, 0x42, 0x3b, 0xa,
0x9, 0x69, 0x56, 0x61, 0x6c, 0x20, 0x26, 0x3d, 0x20, 0x69, 0x41, 0x6e,
0x64, 0x4d, 0x61, 0x73, 0x6b, 0x3b, 0xa, 0x9, 0x72, 0x47, 0x50, 0x49, 0x4f,
0x5f, 0x42, 0x20, 0x26, 0x3d, 0x20,
0x69, 0x41, 0x6e, 0x64, 0x4d, 0x61, 0x73, 0x6b, 0x3b, 0xa, 0x9, 0x72, 0x47,
0x50, 0x49, 0x4f, 0x5f, 0x42, 0x5f, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f,
0x45, 0x6e, 0x61, 0x62,
0x6c, 0x65, 0x20, 0x26, 0x3d, 0x20, 0x69, 0x41, 0x6e, 0x64, 0x4d, 0x61,
0x73, 0x6b, 0x3b, 0x9, 0xa, 0x9, 0x72, 0x47, 0x50, 0x49, 0x4f, 0x5f, 0x42,
0x5f, 0x49, 0x6e, 0x70, 0x75, 0x74,
0x5f, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x7c, 0x3d, 0x20, 0x69,
0x4f, 0x72, 0x4d, 0x61, 0x73, 0x6b, 0x3b, 0xa, 0xa, 0x9, 0x72, 0x65, 0x74,
0x75, 0x72, 0x6e, 0x20, 0x69, 0x56,
0x61, 0x6c, 0x3b, 0xa, 0x7d, 0xa, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0xa,
0xa, 0x76, 0x6f, 0x69, 0x64, 0xa, 0x74, 0x65, 0x73, 0x74, 0x42, 0x75, 0x67,
0x20, 0x28, 0x76, 0x6f, 0x69,
0x64, 0x29, 0xa, 0x7b, 0xa, 0x20, 0x20, 0x41, 0x53, 0x53, 0x45, 0x52, 0x54,
0x20, 0x28, 0x31, 0x29, 0x3b, 0xa, 0x7d, 0xa, 0xa};
char* end = p + (sizeof(p) / sizeof(p[0]));
const char* eol = NULL;
char* start;
int i = 0;
do {
start = p + len;
const char* eol = svn_eol__find_eol_start(start, end - start);
len += (eol ? eol : end) - start;
i++;
} while (((end - p) > len + 2) && i < 100);
}
```
```
$ gcc eol.c -std=gnu90 -O2 -mavx -o eol && ./eol
$ gcc eol.c -std=gnu90 -O2 -mavx -o eol -fno-vect-cost-model && ./eol
Segmentation fault (core dumped) ./eol
$ valgrind ./eol
[...]
==714951== Process terminating with default action of signal 11 (SIGSEGV):
dumping core
==714951== General Protection Fault
==714951== at 0x10868D: svn_eol__find_eol_start (in
/home/sam/bugs/subversion/subversion-1.14.5/build-maybe/eol)
==714951== by 0x10839A: main (in
/home/sam/bugs/subversion/subversion-1.14.5/build-maybe/eol)
==714951==
```
```
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/15/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-15.0.9999/work/gcc-15.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/15
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15
--disable-silent-rules --disable-dependency-tracking
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/15/python
--enable-objc-gc --enable-languages=c,c++,d,go,objc,obj-c++,fortran,ada,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 15.0.9999 p, commit
2f960908caaad18d54ce7cb764ac470656e664c4' --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-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.1 20250225 (experimental)
2d812eecc36e69b5c39ad49b80ab9965c63fdd09 (Gentoo Hardened 15.0.9999 p, commit
2f960908caaad18d54ce7cb764ac470656e664c4)
```