Hi,
when compiling the following code with avr-g++ 4.3.3 using -Wall -O2 -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega1281:
void assertion_lite(void) __attribute__ ((noreturn)); void get_mcusr(void) __attribute__ ((naked, section(".init3"))); void get_mcusr(void) { if (!(SP == RAMEND)) assertion_lite(); }
I get the following assembler:
000003de <_Z9get_mcusrv>: 3de: 8d b7 in r24, 0x3d ; 61 3e0: 9e b7 in r25, 0x3e ; 62 3e2: 8f 5f subi r24, 0xFF ; 255 3e4: 91 42 sbci r25, 0x21 ; 33 3e6: 01 f4 brne .+0 ; 0x3e8 <_Z9get_mcusrv+0xa> 3e8: 4c d0 rcall .+152 ; 0x482 <_Z14assertion_litev> 000003ea <__do_copy_data>: 3ea: 12 e0 ldi r17, 0x02 ; 2 3ec: a0 e0 ldi r26, 0x00 ; 0 . . .
which is obviously wrong, since assertion_lite() is called regardless of the SP check (I don't if this happens because the compiler doesn't correctly handle that the function has no ret instruction due to being in the .initx chain). Has anybody seen this issue before, and if so, is there a way to get around it?
Thanks.
NB. Using -Os or -O1 I don't get this problem (it evaluates to a breq +2 that skips the rcall.