X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Flocals.c;h=024c1c5fc457344f559ced2e3da1964939c2b85b;hb=0614078198d69d3d891fe669e4703e8a60beddca;hp=ffadb1bd502f57eb47468fc679d61979a6307758;hpb=0b186407f1117529f0f6902569f9d24bc8b1b979;p=cc65 diff --git a/src/cc65/locals.c b/src/cc65/locals.c index ffadb1bd5..024c1c5fc 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -52,6 +52,7 @@ #include "standard.h" #include "symtab.h" #include "typeconv.h" +#include "input.h" @@ -270,6 +271,14 @@ static void ParseAutoDecl (Declaration* Decl) /* Mark the variable as referenced */ Sym->Flags |= SC_REF; + /* Make note of auto variables initialized in current block. + ** We abuse the Collection somewhat by using it to store line + ** numbers. + */ + CollReplace (&CurrentFunc->LocalsBlockStack, + (void *)(size_t)GetCurrentLine (), + CollCount (&CurrentFunc->LocalsBlockStack) - 1); + } else { /* Non-initialized local variable. Just keep track of ** the space needed. @@ -489,6 +498,9 @@ void DeclareLocals (void) /* Remember the current stack pointer */ int InitialStack = StackPtr; + /* A place to store info about potential initializations of auto variables */ + CollAppend (&CurrentFunc->LocalsBlockStack, 0); + /* Loop until we don't find any more variables */ while (1) { @@ -538,6 +550,11 @@ void DeclareLocals (void) /* Be sure to allocate any reserved space for locals */ F_AllocLocalSpace (CurrentFunc); + /* No auto variables were inited. No new block on the stack then. */ + if (CollLast (&CurrentFunc->LocalsBlockStack) == NULL) { + CollPop (&CurrentFunc->LocalsBlockStack); + } + /* In case we've allocated local variables in this block, emit a call to ** the stack checking routine if stack checks are enabled. */