https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65657
Bug ID: 65657
Summary: [avr] read from __memx address space tramples argument
to following function
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: jonathan.creekm...@synapse-wireless.com
Created attachment 35207
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35207&action=edit
Test snippet that exhibits the problem.
For an AVR target, the following code that reads from the __memx address space
results in the wrong code and tramples the handle variable:
extern void writeFlashByte(uint8_t byte, uint16_t handle);
void writeBuf(const uint8_t __memx *from, const uint8_t __memx *to)
{
uint16_t handle = ((uint16_t)(((__uint24)to) & 0xUL));
writeFlashByte(*from++, handle++);
}
The relevant assembly code is as follows:
mov r27,r22# Move 'from' out of the way
mov r26,r23# Move 'from' out of the way
mov r21,r24# Move 'from' out of the way
mov r24,r20# Move 'to' into 'handle' for calling writeFlashByte
movw r22,r18 # Move 'to' into 'handle' for calling writeFlashByte
mov r30,r27# Put the relevant bits of 'from' into place to call __xload_1
mov r31,r26# Put the relevant bits of 'from' into place to call __xload_1
call __xload_1 # <-- Returns into r22, corrupting the lower byte of 'handle'
mov r24,r22# Move the result of __xload_1 for calling writeFlashByte
jmp writeFlashByte
The line marked <-- is where the badness occurs. Since __xload_1 returns into
r22, the 'handle' argument to writeFlashByte (which should be in r22 and r23),
gets its r22 portion corrupted by the value __xload_1.
PR target/52484 mentioned adding R22 to the register footprint for xload, but
that was targeted to 4.7.1, so I am not sure why this is failing in 4.8.1.
== compile ==
avr-gcc -save-temps -mmcu=atmega128rfa1 -Os -v -Wall -Wextra -c test.c
== configure ==
../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib
--infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin
--libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib
--enable-long-long --enable-nls --without-included-gettext --disable-libssp
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.8.1 (GCC)