> For some reason, in a certain scenario it is not rewinding the stack
> pointer after returning from a function call. That is, before the
> function call, it pushes arguments to the stack as normal, but
> afterwards it is NOT following up with a "addw sp, #N" instruction.
The cleanup for stack parameters is done for both: for foo by the
callee, for bar by the caller. Which one does it depends on the type of
the function. For details, see section 4.5.1.1, "SDCC calling
convention, version 1" in the manual:
; test2.c: 18: void foo(unsigned long x, unsigned long y, some_t *z) {
; -----------------------------------------
; function foo
; -----------------------------------------
_foo:
; test2.c: 21: (void)z;
; test2.c: 22: }
ldw x, (1, sp)
addw sp, #12
jp (x)
Therefore, execution here goes haywire, because unexpected > values are encountered for stack-held variables (in my original code,
> 'i' became bogus and the for loop exited early).
This, on the other hand, shouldn't happen.
I don't have time to check now, but wonder if that addw sp, #12 should
have been addw sp, #14 instead, so we'd have a bug in tail call
optimization in the callee?
Philipp
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user