[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Proposal for handling alloca(). Anyone see a problem

From: Daniel Glöckner
Subject: Re: [Tinycc-devel] Proposal for handling alloca(). Anyone see a problem with it?
Date: Tue, 8 May 2007 20:04:57 +0200
User-agent: Mutt/

On Tue, May 08, 2007 at 07:08:10PM +0200, Philippe Ribet wrote:
>    } // this closes block 1 thus freeing local variable 2

Tinycc doesn't free local variables when leaving a block.
Variables for all blocks are allocated on the stack when the function is

There is a variable loc in tinycc that is set to 0 when a function
prolog is generated. Each time the compiler needs some space for a
variable, loc is decremented by the number of bytes (and properly
aligned afterwards). The resulting value of loc becomes the frame
pointer relative address of the variable. When the function epilog is
generated, the current value of loc is patched into the prolog to be
added to the stack pointer on function entry.


void f()
    char x[1000];
    char x[1000];
    char x[1000];

will add -3000 to the stack pointer (after it has been copied to the
frame pointer). To save some stack space, we could do locSaved=loc
when a new block is parsed and set locMin=min(loc,locSaved) at the end
of the block. Then in the function epilog we patch the value of locMin
into the prolog. Unfortunately this breaks ({int x=1; x;}).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]