https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123853
Graeme Harker <graeme.harker at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |graeme.harker at gmail dot com
--- Comment #28 from Graeme Harker <graeme.harker at gmail dot com> ---
Created attachment 66233
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66233&action=edit
post-increment test case (copy loop)
A smaller case, with post-increment instead of pre-decrement, from a plain
copy loop (attached as autoinc.c):
unsigned long table[256];
void copy_table(void)
{
for (int i = 0; i < 256; i++)
((unsigned long *)0x13000)[i] = table[i];
}
m68k-linux-gnu-gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0, -O2 or -O3 with any
-m680x0 (not -O1 or -Os):
lea table,%a0
move.l #77824,%d0
sub.l %a0,%d0
.L2:
move.l (%a0)+,(%a0,%d0.l)
cmp.l #table+1024,%a0
jne .L2
so every longword is stored 4 bytes too high and the last one lands past the
end of the destination. We hit this in a memory test on a 68030 board, where
it overwrote the word after the buffer.
On what the processor does, since comment 15 of PR123076 wonders about
emulator differences: the destination address uses %a0 after the increment
on a real MC68030 and under qemu-system-m68k 10.2.1 (-M virt, 68040) alike.
autoinc-run.c (attached) executes the one instruction and prints where the
longword went; both print "00000000 11111111 00000000". I have not tried
qemu-user or Aranym.
In a larger program we have also seen the auto-incremented register used as
the index of the destination, move.l (%a0)+,(%a1,%a0.l), with the same
result. I have no reduced case for that form, but a fix probably needs to
cover it as well as the base-register form.
I have not tested the patch from comment 18 against either.