Bug 25722 - Stackpointer is not restored correct at end of function
Summary: Stackpointer is not restored correct at end of function
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2006-01-09 12:31 UTC by Bjarne Laursen
Modified: 2010-07-19 13:43 UTC (History)
5 users (show)

See Also:
Target: avr
Known to work:
Known to fail:
Last reconfirmed:

Testcase (18.63 KB, application/x-zip-compressed)
2006-01-09 12:33 UTC, Bjarne Laursen

Note You need to log in before you can comment on or make changes to this bug.
Description Bjarne Laursen 2006-01-09 12:31:10 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.
Comment 1 Bjarne Laursen 2006-01-09 12:33:42 UTC
Created attachment 10598 [details]

Testcase including debug code for avr-studio 4. When the funtion 'Evaluate' exits the program chrashes
Comment 2 berndtrog 2006-01-10 16:56:17 UTC
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!

Comment 3 Anitha Boyapati 2010-07-19 12:56:14 UTC
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.
119:          Evaluate();
+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.

Comment 4 Anitha Boyapati 2010-07-19 13:03:13 UTC
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() ]
Comment 5 Eric Weddington 2010-07-19 13:43:48 UTC
Closing as WORKSFORME based on comments #3, #4.