- ensure that STOP_RENDERING is set up everywhere it needs to be
diff --git a/mako/codegen.py b/mako/codegen.py
index 0226415..3c0bad4 100644
--- a/mako/codegen.py
+++ b/mako/codegen.py
@@ -19,7 +19,8 @@
 # names which are hardwired into the
 # template and are not accessed via the
 # context itself
-RESERVED_NAMES = set(['context', 'loop', 'UNDEFINED', 'STOP_RENDERING'])
+TOPLEVEL_DECLARED = set(["UNDEFINED", "STOP_RENDERING"])
+RESERVED_NAMES = set(['context', 'loop']).union(TOPLEVEL_DECLARED)
 
 def compile(node,
                 uri,
@@ -243,7 +244,7 @@
         module_identifiers.topleveldefs = \
             module_identifiers.topleveldefs.\
                 union(main_identifiers.topleveldefs)
-        module_identifiers.declared.add("UNDEFINED")
+        module_identifiers.declared.update(TOPLEVEL_DECLARED)
         if impcode:
             module_identifiers.declared.update(impcode.declared_identifiers)
 
diff --git a/test/test_template.py b/test/test_template.py
index a6a491f..f551230 100644
--- a/test/test_template.py
+++ b/test/test_template.py
@@ -1264,13 +1264,13 @@
         eq_(
             ModuleInfo.get_module_source_metadata(t.code, full_line_map=True),
             {
-                'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
-                                    0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 8,
-                                    8, 8, 8, 8, 8, 8],
+                'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7,
+                    8, 8, 8, 8, 8, 8, 8],
                 'source_encoding': 'ascii',
                 'filename': None,
-                'line_map': {34: 28, 14: 0, 21: 1, 22: 4, 23: 5, 24: 5,
-                                    25: 5, 26: 7, 27: 8, 28: 8},
+                'line_map': {35: 29, 15: 0, 22: 1, 23: 4, 24: 5, 25: 5,
+                             26: 5, 27: 7, 28: 8, 29: 8},
                 'uri': '/some/template'
             }
 
@@ -1293,17 +1293,19 @@
         eq_(
             ModuleInfo.get_module_source_metadata(t.code, full_line_map=True),
             {
-                'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-                            0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 7, 7,
-                            7, 7, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8,
-                            8, 8, 8, 8, 8, 8, 8],
+                'full_line_map': [
+                    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+                    1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 7,
+                    7, 7, 7, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8,
+                    8, 8, 8, 8, 8, 8, 8, 8],
                 'source_encoding': 'ascii',
                 'filename': None,
-                'line_map': {33: 10, 39: 8, 45: 8, 14: 0, 51: 45, 23: 1,
-                                24: 4, 25: 5, 26: 5, 27: 5, 28: 7},
+                'line_map': {34: 10, 40: 8, 46: 8, 15: 0, 52: 46,
+                             24: 1, 25: 4, 26: 5, 27: 5, 28: 5, 29: 7},
                 'uri': '/some/template'}
         )
 
+
 class PreprocessTest(TemplateTest):
     def test_old_comments(self):
         t = Template("""