Commit 30f616cd authored by Stefan Behnel's avatar Stefan Behnel

Validate that all temps were correctly released at the end of a function.

parent df0047fa
...@@ -735,6 +735,20 @@ class FunctionState(object): ...@@ -735,6 +735,20 @@ class FunctionState(object):
self.should_declare_error_indicator = False self.should_declare_error_indicator = False
self.uses_error_indicator = False self.uses_error_indicator = False
# safety checks
def validate_exit(self):
# validate that all allocated temps have been freed
if self.temps_allocated:
leftovers = set(self.all_managed_temps()).difference(self.all_free_managed_temps())
if leftovers:
msg = "Temps left over at end of '%s': %s" % (
self.scope.name,
', '.join(map(str, sorted(leftovers, key=operator.itemgetter(0)))),
)
print(msg)
#raise RuntimeError(msg)
# labels # labels
def new_label(self, name=None): def new_label(self, name=None):
...@@ -1860,6 +1874,7 @@ class CCodeWriter(object): ...@@ -1860,6 +1874,7 @@ class CCodeWriter(object):
self.funcstate = FunctionState(self, scope=scope) self.funcstate = FunctionState(self, scope=scope)
def exit_cfunc_scope(self): def exit_cfunc_scope(self):
self.funcstate.validate_exit()
self.funcstate = None self.funcstate = None
# constant handling # constant handling
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment