This is the mail archive of the gcc-patches@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]

fix for -O3 -g testsuite failures for dwarf2 targets


Targets using DWARF2 have new gcc testsuite failures at -O3 -g.  The culprit
is this change.

Wed Sep 15 21:37:06 1999  Mark Mitchell  <mark@codesourcery.com>

	* integrate.c (integrate_decl_tree): Don't use pushlevel,
	pushdecl, or poplevel to build up the new BLOCK tree.

Here is a simple testcase, extracted from gcc.c-torture/compile/920625-1.c.

inline int
sub ()
{
  sub2 ();
}

int
sub2 ()
{
  sub ();
}

In dwarf2out.c, we see three different decls for sub2.  There is the block
local implicit declaration in sub, and the global extern declaration.  After
sub is inlined into sub2, we now have a third decl whose abstract origin is
the block local decl in sub.

When we emit debug info for sub, we do not emit debug info for the block
local implicit declaration, because it is just a declaration.

When we emit debug info for sub2, we try to emit debug info for the third
decl, and we abort in add_abstract_origin_attribute because origin_die
is NULL.  It is NULL because we did not emit debug info for the block local
decl above.

This used to work because integrate_decl_tree called pushdecl when creating
the third decl, and pushdecl set DECL_CONTEXT to NULL.  This causes dwarf2out.c
to ignore the decl because it is just a function declaration.

The new code unconditionally sets DECL_CONTEXT.  This seems wrong.

Unfortunately, every front end sets DECL_CONTEXT slightly differently,
so we may need a new front end callback to get this right.  For now, I
just use the C version of the DECL_CONTEXT code from pushdecl.

An alternative solution might be to set DECL_CONTEXT for the new decl only
if the DECL_CONTEXT for the old decl is non-null.  E.g.
	if (DECL_CONTEXT (t))
	  DECL_CONTEXT (d) = current_function_decl;
I am not convinced that this is right either.

If there is a problem here, it will probably only show up as problems with
the debug info.  The gdb testsuite might be useful for figuring out what
the correct solution is here.

This patch is sufficient to build a dwarf2 toolchain and run the gcc testsuite
without any of the new -O3 -g failures.

Wed Oct 20 12:34:24 1999  Jim Wilson  <wilson@cygnus.com>

	* integrate.c (integrate_decl_tree): Set DECL_CONTEXT to 0 if this is
	a local extern function declaration.

*** integrate.c.orig	Wed Oct 20 12:38:44 1999
--- integrate.c	Wed Oct 20 12:39:49 1999
*************** integrate_decl_tree (let, map)
*** 1419,1428 ****
--- 1419,1441 ----
        if (DECL_LANG_SPECIFIC (d))
  	copy_lang_decl (d);
  
+       /* ??? We used to call pushdecl here, but that does not work now that
+ 	 we generate entire functions as trees.  We only want the pushdecl
+ 	 code that sets DECL_CONTEXT.  Each front end sets DECL_CONTEXT
+ 	 slightly differently though, so we may need new callbacks to the
+ 	 front-ends to do this right.  For now, we just use the code from the
+ 	 C front end and hope that is sufficient.  Alternatively, we could
+ 	 set DECL_CONTEXT (d) here only if DECL_CONTEXT (t) is non-null.  */
        /* This new declaration is now in the scope of the function into
  	 which we are inlining the function, not the function being
  	 inlined.  */
        DECL_CONTEXT (d) = current_function_decl;
+       /* A local extern declaration for a function doesn't constitute nesting.
+ 	 A local auto declaration does, since it's a forward decl
+ 	 for a nested function coming later.  */
+       if (TREE_CODE (d) == FUNCTION_DECL && DECL_INITIAL (d) == 0
+ 	  && DECL_EXTERNAL (d))
+ 	DECL_CONTEXT (d) = 0;
  
        /* Add this declaration to the list of variables in the new
  	 block.  */


Jim


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