http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51002
Bug #: 51002 Summary: SP_H register is used even on targets that do not have it (eg attiny26) Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: w...@hhhh.org Target: avr Not all of the AVR parts implement a full 16-bit-wide stack pointer; on (for example) the ATtiny26/ATtiny261, the stack pointer is 8 bits wide and the SP_H register (at 0x3E) is not implemented. GCC 4.6.2 is smart enough to manipulate only the lower 8 bits of the stack pointer in the function prologue/epilogue, but it still attempts to load the upper 8 bits from the nonexistent SP_H register, resulting in the upper 8 bits of any stack-relative pointer containing a garbage value: extern void bar(char *c); void foo() { char buf[16]; bar(buf); } $ avr-gcc -Os -fverbose-asm -S -mmcu=attiny26 stkbuf.c foo: push r28 ; push r29 ; in r28,__SP_L__ ; in r29,__SP_H__ ; subi r28,lo8(-(-16)) ; , out __SP_L__,r28 ; /* prologue: function */ /* frame size = 16 */ /* stack size = 18 */ .L__stack_usage = 18 mov r24,r28 ; , mov r25,r29 ; , adiw r24,1 ; , rcall bar ; [etc]