public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Partially fix PR debug/53927
@ 2014-05-09  8:24 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2014-05-09  8:24 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

Hi,

this makes sure we always generate a static chain for nested functions at -O0 
and force it onto the stack in this case so that DW_AT_static_link is always 
meaningful (but not necessarily fully correct, see the audit trail).

FWIW this has been done for years in AdaCore's compilers.

Tested on x86_64-suse-linux, OK for the mainline?


2014-05-09  Eric Botcazou  <ebotcazou@adacore.com>

	PR debug/53927
	* function.c (instantiate_decls): Process the saved static chain.
	(expand_function_start): If not optimizing, save the static chain
	onto the stack.
	* tree-nested.c (convert_all_function_calls): Always create the static
	chain for nested functions if not optimizing.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 2451 bytes --]

Index: function.c
===================================================================
--- function.c	(revision 210256)
+++ function.c	(working copy)
@@ -1872,6 +1872,11 @@ instantiate_decls (tree fndecl)
 	}
     }
 
+  /* Process the saved static chain if it exists.  */
+  decl = DECL_STRUCT_FUNCTION (fndecl)->static_chain_decl;
+  if (decl && DECL_HAS_VALUE_EXPR_P (decl))
+    instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl)));
+
   /* Now process all variables defined in the function or its subblocks.  */
   instantiate_decls_1 (DECL_INITIAL (fndecl));
 
@@ -4805,6 +4810,20 @@ expand_function_start (tree subr)
       if (MEM_P (chain)
 	  && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0)))
 	set_dst_reg_note (insn, REG_EQUIV, chain, local);
+
+      /* If we aren't optimizing, save the static chain onto the stack.  */
+      if (!optimize)
+	{
+	  tree saved_static_chain_decl
+	    = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL,
+			  DECL_NAME (parm), TREE_TYPE (parm));
+	  rtx saved_static_chain_rtx
+	    = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
+	  SET_DECL_RTL (saved_static_chain_decl, saved_static_chain_rtx);
+	  emit_move_insn (saved_static_chain_rtx, chain);
+	  SET_DECL_VALUE_EXPR (parm, saved_static_chain_decl);
+	  DECL_HAS_VALUE_EXPR_P (parm) = 1;
+	}
     }
 
   /* If the function receives a non-local goto, then store the
Index: tree-nested.c
===================================================================
--- tree-nested.c	(revision 210256)
+++ tree-nested.c	(working copy)
@@ -2218,11 +2218,21 @@ convert_all_function_calls (struct nesti
   struct nesting_info *n;
 
   /* First, optimistically clear static_chain for all decls that haven't
-     used the static chain already for variable access.  */
+     used the static chain already for variable access.  But always create
+     it if not optimizing.  This makes it possible to reconstruct the static
+     nesting tree at run time and thus to resolve up-level references from
+     within the debugger.  */
   FOR_EACH_NEST_INFO (n, root)
     {
       tree decl = n->context;
-      if (!n->outer || (!n->chain_decl && !n->chain_field))
+      if (!optimize)
+	{
+	  if (n->inner)
+	    (void) get_frame_type (n);
+	  if (n->outer)
+	    (void) get_chain_decl (n);
+	}
+      else if (!n->outer || (!n->chain_decl && !n->chain_field))
 	{
 	  DECL_STATIC_CHAIN (decl) = 0;
 	  if (dump_file && (dump_flags & TDF_DETAILS))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-05-09  8:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-09  8:24 [patch] Partially fix PR debug/53927 Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).