If i use global register variables that are used and updated inside an interrupt the optimizer produces broken code. Code example: register volatile unsigned char timer0_h8 asm("r3"); volatile unsigned char timer0_h8_buf = 0;
void foo(void) { timer0_h8_buf = timer0_h8; return; } ISR(TIMER0_OVF_vect) { timer0_h8++; } produces: 2432 0b5a 1092 0000 sts timer0_h8_buf,__zero_reg__ ; timer0_h8_buf, instead of this when no optimization is used: 3248 104a 832D mov r24,r3 ; timer0_h8.47, timer0_h8 3249 104c 8093 0000 sts timer0_h8_buf,r24 ; timer0_h8_buf, timer0_h8.47 -- Summary: optimization fails when register variables are used for an interrupt Product: gcc Version: 4.4.2 Status: UNCONFIRMED Severity: critical Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hendrixgr at gmail dot com GCC build triplet: Linux i386 GCC host triplet: Linux ubuntu 9.04 GCC target triplet: avr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41849