GCC Bugzilla – Bug 25722
Stackpointer is not restored correct at end of function
Last modified: 2010-07-19 13:43:48 UTC
In at least one case where a lot of local variables have been used in a function the stackpointer is restored from a register pair where the it have never been saved.
Created attachment 10598 [details]
Testcase including debug code for avr-studio 4. When the funtion 'Evaluate' exits the program chrashes
Only 3.4.x seems allocate a frame pointer in the function 'Evaluate'.
It would be interesting if this bug can be triggered in 4.x!
When I tried with AVR Studio 4.18, Build 684, the program didn't crash.
I think the issue is not with compiler. Disassembly looks proper and call to Evaluate() is returned. This can be verified by using breakpoints in assembly statements.
+0000023E: 940E0056 CALL 0x00000056 Call subroutine
+00000240: CFFF RJMP PC-0x0000 Relative jump
However when I tried to put breakpoint for 'while' statement, it did not work out as the corresponding source line couldn't be found in the program memory. This differs from the expected behavior.
SSA pass pass_remove_useless_stmts() removes useless statements and any code beyond statements like "while(1);" will not be generated. This might be why the breakpoint at "while(TRUE);" in the testcase is not recognised [and hence the simulation looks like hanged/or not returned from evaluate() ]
Closing as WORKSFORME based on comments #3, #4.