https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122140
Bug ID: 122140
Summary: bpf: wrong code for __builtin_memmove
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Blocks: 118443
Target Milestone: ---
Target: bpf-unknown-none
The following function is miscompiled at -O1 and higher optimization levels:
char a[32];
void foo (void)
{
__builtin_memmove (a+1, a, 4);
}
The generated code is:
foo:
lddw %r0,a+1
lddw %r1,a
jge %r1,%r0,.L2
ldxb %r2,[%r1+4]
stxb [%r0+4],%r2
ldxb %r3,[%r1+3]
stxb [%r0+3],%r3
ldxb %r4,[%r1+2]
stxb [%r0+2],%r4
ldxb %r5,[%r1+1]
stxb [%r0+1],%r5
exit
.L2:
ldxb %r9,[%r1+0]
stxb [%r0+0],%r9
stxb [%r0+1],%r9
stxb [%r0+2],%r9
stxb [%r0+3],%r9
exit
wich performs an operation equivalent to: __builtin_memmove (a+2, a+1, 4).
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing