BUGFIX: Occurrence of multiple macro symbols in one tuple could lead to infinite loop.

The mechanism with the next pointers for tac's was working fine as long as all
tac's were unique by construction. The macro mechanism made it possible for
the same tac to occur twice in the tree. This could lead to an infinite loop.

Now we make explicit copies of the top-level tac. This should fix the problem
caused by the tuple parsing.

A more fundamental solution is to make a deep copy of the substituted terms.
This commit is contained in:
Cas Cremers 2012-11-23 11:55:29 +01:00
parent 1b4eb7cb54
commit a71fe51036
3 changed files with 18 additions and 1 deletions

View File

@ -423,7 +423,7 @@ basicormacro : ID
Tac macrotac; Tac macrotac;
macrotac = (Tac) l->data; macrotac = (Tac) l->data;
t = macrotac->t2.tac; t = tacCopy(macrotac->t2.tac);
} }
$$ = t; $$ = t;
} }

View File

@ -52,6 +52,22 @@ tacDone (void)
} }
} }
//! Copy a tac
Tac
tacCopy(Tac c)
{
Tac newTac;
newTac = (Tac) malloc (sizeof (struct tacnode));
memcpy (newTac, c, sizeof (struct tacnode));
// Store in taclist
newTac->allnext = allocatedTacs;
allocatedTacs = newTac;
return newTac;
}
//! Create a tac node of some type //! Create a tac node of some type
Tac Tac
tacCreate (int op) tacCreate (int op)

View File

@ -90,6 +90,7 @@ typedef struct tacnode *Tac;
void tacInit (void); void tacInit (void);
void tacDone (void); void tacDone (void);
Tac tacCopy(Tac c);
Tac tacCreate (int op); Tac tacCreate (int op);
Tac tacSymb (char *s); Tac tacSymb (char *s);
Tac tacJoin (int op, Tac t1, Tac t2, Tac t3); Tac tacJoin (int op, Tac t1, Tac t2, Tac t3);