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]
Other format: [Raw text]

Re: [C++ PATCH] Fix debuginfo with nrv (PR debug/44367)


On Wed, Jun 02, 2010 at 01:43:06AM -0400, Jason Merrill wrote:
> On 06/01/2010 05:22 PM, Jakub Jelinek wrote:
> >When the C++ FE NRV optimizes some variable, we end up with
> >two DIEs for the same variable, one (from the RESULT_DECL) with
> >the correct location, the other one (usually in a DW_TAG_lexical_block
> >as child of the DW_TAG_subprogram) with a wrong location.
> >Even a stack slot is allocated for it at -O0.
> >
> >The following patch fixes it (DECL_IGNORED_P makes sure the wrong one
> >that isn't used anymore doesn't make it into debug info, DECL_VALUE_EXPR
> >ensures that a stack slot isn't even allocated for it).
> 
> Hmm...it seems to me that a better approach would be to set
> DECL_VALUE_EXPR on the VAR_DECL as in your patch, but not set
> DECL_IGNORED_P; rather, remove all the "copy debug info" bits so
> that we only get debug info for the user-declared variable.

That works too, though on the testcase from the PR a is no longer in scope
on the } line (and, given that there are no insns with locus of the return
a; stmt at -O0, that means the last line where it can be inspected is on the
line with the call).  But perhaps that is a generic -g -O0 issue that should
be addressed separately.  Say for:
void
foo (void)
{
  int i = 6;
  return;
}
(talking about explicit return here, not implicit one) gcc/g++ -g -O0
doesn't emit any insns with locus of the return line.  There is insn with
int i = 6; line, but there i still isn't 6, and then there is epilogue with
} line.  When compiled with gcc, i is said to be in scope at that line still
and so one sees i is 6, with g++ i is in a lexical block that lives only
after prologue and before epilogue and so at no point in the function gdb
will print i is 6.  Perhaps for return stmts that expand into no code and
are explicit (i.e. have some source location) we should emit a nop with that
locus for -O0...

2010-06-02  Jakub Jelinek  <jakub@redhat.com>

	PR debug/44367
	* semantics.c (finalize_nrv): Don't copy DECL_ARTIFICIAL, DECL_IGNORED_P,
	DECL_SOURCE_LOCATION and DECL_ABSTRACT_ORIGIN from var to result.
	Set DECL_VALUE_EXPR on var.

--- gcc/cp/semantics.c.jj	2010-05-28 14:35:53.000000000 +0200
+++ gcc/cp/semantics.c	2010-06-02 07:58:43.000000000 +0200
@@ -3504,14 +3504,15 @@ finalize_nrv (tree *tp, tree var, tree r
 {
   struct nrv_data data;
 
-  /* Copy debugging information from VAR to RESULT.  */
+  /* Copy name from VAR to RESULT.  */
   DECL_NAME (result) = DECL_NAME (var);
-  DECL_ARTIFICIAL (result) = DECL_ARTIFICIAL (var);
-  DECL_IGNORED_P (result) = DECL_IGNORED_P (var);
-  DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var);
-  DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var);
   /* Don't forget that we take its address.  */
   TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
+  /* Finally set DECL_VALUE_EXPR to avoid assigning
+     a stack slot at -O0 for the original var and debug info
+     uses RESULT location for VAR.  */
+  SET_DECL_VALUE_EXPR (var, result);
+  DECL_HAS_VALUE_EXPR_P (var) = 1;
 
   data.var = var;
   data.result = result;


	Jakub


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