alloca() is usually implemented on architectures that have separate base-pointer and stack-pointer. The base pointer is used to provide a consistent base for addressing the local frame on the stack. The stack pointer can grow down any time (eg. hardware interrupts, or complex expressions being stacked as parameters).
Since this is the case on the x86 (SP and BP), and since BP is restored from its local frame, and SP adjusted to that, the correct implementation of alloca() (well, AN arguably correct implementation) is to simply return SP, and decrement it by the request amount, rounded up to the basic stack alignment. But, you may be using alloca() in a parameter sub-expression! (at which point later earlier parameters can no longer be correctly retrieved). Which is the problem you are thinking about... I suggest that on the each occurrence of alloca() in an expression that is a parameter, generate a subtract from SP. Generate a copy of the total parameter bytes (to date) to just before the new SP. Note that attempting a malloc()/free() will not work: unless you can guarantee the longjmp implementation (and carry information on each parameter). It is still tricky: consider a setjmp() before the alloca() function is invoked. So, all jmpbuf need to be chained, and since *they* can be dynamically allocated, including alloca(), well, its tricky... My solution is simple, and will work. _______________________________________________ Tinycc-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/tinycc-devel
