This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug debug/10718] nested locals with same name broken with gcc HEAD 2003-04-11


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10718



------- Additional Comments From zack at codesourcery dot com  2003-06-25 18:31 -------
Subject:  PATCH: fix dwarf2 output for local variables in nested
 blocks


Bug #10718 reports incorrect debug information generated for the inner
'local' declaration in a construct like

void foo(int arg) {
  int local;
  {
    int local;
  }
}

The problem is actually more general; any variable declared one level
down from the outermost scope of a function will be incorrectly
recorded as belonging to the outermost scope.

What's going on is, formerly all front ends would generate a tree like
this for the above:

 <function_decl foo
   arguments <parm_decl arg>
   initial <block
     vars <>
     subblocks <block
       vars <var_decl local>
       subblocks <block
         vars <var_decl local>>>>>

Note the empty BLOCK in between the FUNCTION_DECL and the BLOCK
containing the outer 'local' decl.  This is an artifact of the
way the C front end originally managed its internal "binding_level"
structures.  It used to make a distinction between the binding level
used for the parameters, and the binding level used for variables at
the outermost scope of the function definition.  This distinction is
bogus: the C standard says those are the same scope.  However, that's
the way it used to do it, and some language-independent parts of the
compiler expect that BLOCK in there.  In particular, dwarf2out.c
(in cooperation with stmt.c) special cases a BLOCK that is the
grandchild of a FUNCTION_DECL, and does not generate a
DW_TAG_lexical_block node for it.

Back in April I changed the C front end not to do this silly thing
anymore; it now generates

 <function_decl foo
   arguments <parm_decl arg>
   initial <block
       vars <var_decl local>
       subblocks <block
         vars <var_decl local>>>>

Therefore dwarf2out.c needs to understand that a BLOCK which is the
grandchild of a FUNCTION_DECL is not special -- when the C or ObjC
front end generated it (the code for this is shared).  Other front
ends are still generating the empty BLOCK.  So this patch adds a
boolean to the langhooks structure, which notifies
stmt.c:is_body_block to do the right thing, and its callers follow.

Language front end maintainers should consider whether they really
need this extra BLOCK.  If the equivalent of

void foo(int i) { double i; }

is ill-formed in your language, you probably have some kludges in your
front end that you could get rid of.

Bootstrapped i686-linux.  I do not see a practical way to get a
testcase for this into the GCC testsuite; it could probably be done in
the GDB testsuite but I don't know how.

zw


        PR 10178
        * langhooks.h (struct lang_hooks): Add no_body_blocks bool.
        * langhooks-def.h (LANG_HOOKS_NO_BODY_BLOCKS): New; default false.
        * c-lang.c, objc/objc-lang.c: Override LANG_HOOKS_NO_BODY_BLOCKS
        to true.
        * stmt.c (is_body_block): If lang_hooks.no_body_blocks, always
        return 0.

===================================================================
Index: langhooks-def.h
--- langhooks-def.h	24 Jun 2003 11:53:53 -0000	1.51
+++ langhooks-def.h	25 Jun 2003 17:22:39 -0000
@@ -107,6 +107,7 @@ void write_global_declarations PARAMS ((
 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lhd_set_decl_assembler_name
 #define LANG_HOOKS_CAN_USE_BIT_FIELDS_P lhd_can_use_bit_fields_p
 #define LANG_HOOKS_HONOR_READONLY	false
+#define LANG_HOOKS_NO_BODY_BLOCKS	false
 #define LANG_HOOKS_PRINT_STATISTICS	lhd_do_nothing
 #define LANG_HOOKS_PRINT_XNODE		lhd_print_tree_nothing
 #define LANG_HOOKS_PRINT_DECL		lhd_print_tree_nothing
@@ -266,6 +267,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_SET_DECL_ASSEMBLER_NAME, \
   LANG_HOOKS_CAN_USE_BIT_FIELDS_P, \
   LANG_HOOKS_HONOR_READONLY, \
+  LANG_HOOKS_NO_BODY_BLOCKS, \
   LANG_HOOKS_PRINT_STATISTICS, \
   LANG_HOOKS_PRINT_XNODE, \
   LANG_HOOKS_PRINT_DECL, \
===================================================================
Index: langhooks.h
--- langhooks.h	24 Jun 2003 11:53:54 -0000	1.59
+++ langhooks.h	25 Jun 2003 17:22:39 -0000
@@ -328,6 +328,11 @@ struct lang_hooks
   /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored.  */
   bool honor_readonly;
 
+  /* Nonzero if this front end does not generate a dummy BLOCK between
+     the outermost scope of the function and the FUNCTION_DECL.  See
+     is_body_block in stmt.c, and its callers.  */
+  bool no_body_blocks;
+
   /* The front end can add its own statistics to -fmem-report with
      this hook.  It should output to stderr.  */
   void (*print_statistics) PARAMS ((void));
===================================================================
Index: stmt.c
--- stmt.c	16 Jun 2003 11:30:22 -0000	1.308
+++ stmt.c	25 Jun 2003 17:22:42 -0000
@@ -3511,6 +3511,9 @@ int
 is_body_block (stmt)
      tree stmt;
 {
+  if (lang_hooks.no_body_blocks)
+    return 0;
+
   if (TREE_CODE (stmt) == BLOCK)
     {
       tree parent = BLOCK_SUPERCONTEXT (stmt);
===================================================================
Index: c-lang.c
--- c-lang.c	22 Jun 2003 12:55:44 -0000	1.104
+++ c-lang.c	25 Jun 2003 17:22:39 -0000
@@ -67,6 +67,8 @@ static int c_init_options (void);
 #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
 #undef LANG_HOOKS_STATICP
 #define LANG_HOOKS_STATICP c_staticp
+#undef LANG_HOOKS_NO_BODY_BLOCKS
+#define LANG_HOOKS_NO_BODY_BLOCKS true
 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL c_warn_unused_global_decl
 #undef LANG_HOOKS_PRINT_IDENTIFIER
===================================================================
Index: objc/objc-lang.c
--- objc/objc-lang.c	7 Jun 2003 11:10:46 -0000	1.30
+++ objc/objc-lang.c	25 Jun 2003 17:22:42 -0000
@@ -65,6 +65,8 @@ static int objc_init_options            
 #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
 #undef LANG_HOOKS_STATICP
 #define LANG_HOOKS_STATICP c_staticp
+#undef LANG_HOOKS_NO_BODY_BLOCKS
+#define LANG_HOOKS_NO_BODY_BLOCKS true
 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
 #undef LANG_HOOKS_PRINT_IDENTIFIER


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]