https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123032
Bug ID: 123032
Summary: [16 Regression] wrong code on libsodium-1.0.20 since
r16-5780-g65a3849eb46df2 (possibly fixed by
r16-5849-g4a1247a3b070cd)
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
A few days ago I noticed gcc-master to miscompile libsodium-1.0.20 on
i686-linux. By the time I extracted the smaller example it does not reproduce
on master any more after r16-5849-g4a1247a3b070cd.
In IRC I asked if the fix could be related, Andrew suspects it might not:
pinskia | because there is no early break in the memmove like code
Filing the bug to confirm the change is intentional and not masking another
bug.
Thus, on r16-5780-g65a3849eb46df2 minimal reproducer fails as:
// $ cat a.c
typedef unsigned char u8;
typedef unsigned int u32;
typedef struct {
u32 pad; // important
u8 buf[64];
} s_t;
__attribute__((noipa))
void h_bad(s_t *state, const u8 *in, u32 inlen) {
for (u32 i = 0; i < inlen; i++) {
state->buf[i] = in[i];
}
}
__attribute__((noipa))
void h_good(s_t *state, const u8 *in, u32 inlen) {
for (u32 i = 0; i < inlen; i++) {
asm volatile("" ::: "memory"); // break vectorizer
state->buf[i] = in[i];
}
}
void h(s_t *state, const u8 *in, u32 inlen) {
s_t s1 = {};
s_t s2 = {};
h_good(&s1, in, inlen);
h_bad(&s2, in, inlen);
if (__builtin_memcmp(&s1, &s2, sizeof(s1)) != 0) {
__builtin_trap();
}
}
int main(void) {
s_t s = {};
const u8 in[] =
"0123456789" /* 0 */
" 0123456789"
" 0123456789"
" 0123456789"
" 0123456789"
;
for (u32 o = 0; o < 10; o++) {
__builtin_memset(&s, 0, sizeof(s));
h(&s, &in[o], 33);
}
}
$ gcc/xgcc -Bgcc a.c -o a -O3 && ./a
Illegal instruction (core dumped) ./a
$ gcc/xgcc -Bgcc -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xgcc
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: i686-unknown-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer --enable-languages=c
CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0' LDFLAGS='-O1 -g0'
--build=i686-unknown-linux-gnu --host=i686-unknown-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20251203 (experimental) (GCC)