Peter N Lewis wrote:
The code which generates a dynamic array on the stack in the middle of a procedure (which I never would have suspected you could do in Pascal) appears to corrupt the stack in a way which makes ReturnAddress(0) either return bogus numbers or crash with a bus error. Or more accurately, assigning to sections of the created array corrupts the stack.
I think the problem is that ReturnAddress expects to find the address at 8(0(r30)) (r30 is the frame pointer I believe). But when the frame expands, r30 remains where it is while r1 (sp I think) drops down, and the return address is preserved at 0(r1), and r1 and r30 are no longer equal.
Interestingly, this looks related to the infamous ppc-darwin "non-local-goto" bug http://gcc.gnu.org/ml/gcc-bugs/2003-05/msg01814.html scheduled to be fixed after the NASA puts the first humans on Mars.
Regards,
Adriaan van Os