1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-01 00:57:11 +00:00
This commit is contained in:
laubzega 2018-09-26 00:11:40 -07:00 committed by Oliver Schmidt
parent 4b78d40e97
commit c835f49913
2 changed files with 21 additions and 30 deletions

View File

@ -88,10 +88,8 @@ void FreeSymEntry (SymEntry* E)
TypeFree (E->Type); TypeFree (E->Type);
xfree (E->AsmName); xfree (E->AsmName);
if (E->Flags & SC_LABEL) if (E->Flags & SC_LABEL) {
{ for (i = 0; i < CollCount (E->V.L.DefsOrRefs); i++) {
for (i = 0; i < CollCount (E->V.L.DefsOrRefs); i++)
{
xfree (CollAt(E->V.L.DefsOrRefs, i)); xfree (CollAt(E->V.L.DefsOrRefs, i));
} }

View File

@ -671,8 +671,8 @@ DefOrRef* AddDefOrRef(SymEntry* E, unsigned Flags)
DOR->LocalsBlockNum = (long)CollLast (&CurrentFunc->LocalsBlockStack); DOR->LocalsBlockNum = (long)CollLast (&CurrentFunc->LocalsBlockStack);
DOR->Flags = Flags; DOR->Flags = Flags;
DOR->StackPtr = StackPtr; DOR->StackPtr = StackPtr;
DOR->Depth = CollCount(&CurrentFunc->LocalsBlockStack); DOR->Depth = CollCount (&CurrentFunc->LocalsBlockStack);
DOR->LateSP_Label = GetLocalLabel(); DOR->LateSP_Label = GetLocalLabel ();
return DOR; return DOR;
} }
@ -695,30 +695,21 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags)
NewDOR = AddDefOrRef (Entry, Flags); NewDOR = AddDefOrRef (Entry, Flags);
/* Walk through all occurrences of the label so far and check /* Walk through all occurrences of the label so far and evaluate
if any of them is in a region that would be risky to jump from/to their relationship with the one passed to the function. */
from the place where we are right now. */
for (i = 0; i < CollCount (Entry->V.L.DefsOrRefs); i++) { for (i = 0; i < CollCount (Entry->V.L.DefsOrRefs); i++) {
DOR = CollAt (Entry->V.L.DefsOrRefs, i); DOR = CollAt (Entry->V.L.DefsOrRefs, i);
/* We are only interested in label occurences of type opposite to
the one currently being added, i.e. if we are processing the
definition, we will only check the gotos; if we are processing
a goto statement, we will only look for the label definition. */
/*
if (((DOR->Flags & SC_DEF) != (Flags & SC_DEF)) &&
(CollCount(&CurrentFunc->LocalsBlockStack) == DOR->Depth) &&
(DOR->LocalsBlockNum != (long)CollLast (&CurrentFunc->LocalsBlockStack)))
Error ("Goto from line %d to label \'%s\' can result in a "
"trashed stack", Flags & SC_DEF ? DOR->Line : GetCurrentLine (), Name);
*/
if((DOR->Flags & SC_DEF) && (Flags & SC_REF)) { if((DOR->Flags & SC_DEF) && (Flags & SC_REF)) {
/* We're processing a goto and here is its destination label. /* We're processing a goto and here is its destination label.
This means the difference between SP values is also known, so This means the difference between SP values is already known,
we simply emit SP adjustment code. */ so we simply emit the SP adjustment code. */
if(StackPtr != DOR->StackPtr) if(StackPtr != DOR->StackPtr)
g_space(StackPtr - DOR->StackPtr); g_space (StackPtr - DOR->StackPtr);
if (CollCount(&CurrentFunc->LocalsBlockStack) <= DOR->Depth && /* Are we jumping into same or deeper nesting region? That's risky,
so let's emit a warning. */
if (CollCount (&CurrentFunc->LocalsBlockStack) <= DOR->Depth &&
DOR->LocalsBlockNum != (long)CollLast (&CurrentFunc->LocalsBlockStack)) { DOR->LocalsBlockNum != (long)CollLast (&CurrentFunc->LocalsBlockStack)) {
Warning ("Goto from line %d to label \'%s\' can result in a " Warning ("Goto from line %d to label \'%s\' can result in a "
"trashed stack", DOR->Line, Name); "trashed stack", DOR->Line, Name);
@ -727,11 +718,13 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags)
if((DOR->Flags & SC_REF) && (Flags & SC_DEF)) { if((DOR->Flags & SC_REF) && (Flags & SC_DEF)) {
/* We're processing a label, let's update all gotos encountered /* We're processing a label, let's update all gotos encountered
so far */ so far */
g_defdatalabel(DOR->LateSP_Label); g_defdatalabel (DOR->LateSP_Label);
g_defdata(CF_CONST | CF_INT, StackPtr - DOR->StackPtr, 0); g_defdata (CF_CONST | CF_INT, StackPtr - DOR->StackPtr, 0);
if (CollCount(&CurrentFunc->LocalsBlockStack) >= DOR->Depth && /* Are we jumping into same or deeper nesting region? That's risky,
so let's emit a warning. */
if (CollCount (&CurrentFunc->LocalsBlockStack) >= DOR->Depth &&
DOR->LocalsBlockNum != (long)CollLast (&CurrentFunc->LocalsBlockStack)) { DOR->LocalsBlockNum != (long)CollLast (&CurrentFunc->LocalsBlockStack)) {
Warning ("Goto from line %d to label \'%s\' can result in a " Warning ("Goto from line %d to label \'%s\' can result in a "
"trashed stack", DOR->Line, Name); "trashed stack", DOR->Line, Name);
@ -764,7 +757,7 @@ SymEntry* AddLabelSym (const char* Name, unsigned Flags)
/* We are processing a goto, but the label has not yet been defined */ /* We are processing a goto, but the label has not yet been defined */
if (!SymIsDef (Entry) && (Flags & SC_REF)) { if (!SymIsDef (Entry) && (Flags & SC_REF)) {
g_lateadjustSP(NewDOR->LateSP_Label); g_lateadjustSP (NewDOR->LateSP_Label);
} }
/* Return the entry */ /* Return the entry */