[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] avr-gcc (GCC) 3.4.5 Bug: copying structure through po
From: |
Joerg Wunsch |
Subject: |
Re: [avr-gcc-list] avr-gcc (GCC) 3.4.5 Bug: copying structure through pointer will destroy the pointer |
Date: |
Mon, 6 Feb 2006 22:24:56 +0100 (MET) |
address@hidden wrote:
> I must have mixed up some of my testing results. Thanks to
> lfmorrison from AVRfreaks.
Here's the smallest reproducible test case:
#define STRUCTSIZE 5
struct a {
char z[STRUCTSIZE];
};
extern struct a *ap;
extern struct a b;
void
bug(void)
{
*ap++ = b;
}
It results in:
bug:
/* prologue: frame size=0 */
/* prologue end (size=0) */
lds r24,ap
lds r25,(ap)+1
mov r31,r25
mov r30,r24
ldi r26,lo8(b)
ldi r27,hi8(b)
ldi r18,lo8(5)
.L2:
ld r0,X+
st Z+,r0
subi r18,lo8(-(-1))
adiw r24,5
sts (ap)+1,r25
sts ap,r24
tst r18
brne .L2
/* epilogue: frame size=0 */
ret
By reduzing STRUCTSIZE to 4, the bug disappears, as the implied memory
copy operation will be unrolled:
bug:
/* prologue: frame size=0 */
/* prologue end (size=0) */
lds r30,ap
lds r31,(ap)+1
lds r24,b
lds r25,(b)+1
lds r26,(b)+2
lds r27,(b)+3
st Z+,r24
st Z+,r25
st Z+,r26
st Z+,r27
sts (ap)+1,r31
sts ap,r30
/* epilogue: frame size=0 */
ret
--
cheers, J"org .-.-. --... ...-- -.. . DL8DTL
http://www.sax.de/~joerg/ NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)