Patchwork [C++] Fix debug info for NRV optimized vars (PR debug/46815)

login
register
mail settings
Submitter Jakub Jelinek
Date Dec. 14, 2010, 9:39 a.m.
Message ID <20101214093954.GC27214@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/75476/
State New
Headers show

Comments

Jakub Jelinek - Dec. 14, 2010, 9:39 a.m.
Hi!

cp_genericize is changing addressable RESULT_DECLs into DECL_BY_REFERENCE
references, but nothing was adjusting DECL_VALUE_EXPR of the original NRV
optimized var and thus the debug info for it was incorrect.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-12-14  Jakub Jelinek  <jakub@redhat.com>

	PR debug/46815
	* cp-gimplify.c (cp_genericize): When changing RESULT_DECL
	into invisible reference, change also DECL_VALUE_EXPR of
	NRV optimized variable.

	* g++.dg/guality/pr46815.C: New test.


	Jakub
Jason Merrill - Dec. 15, 2010, 3:54 p.m.
OK.

Jason

Patch

--- gcc/cp/cp-gimplify.c.jj	2010-12-07 17:32:44.000000000 +0100
+++ gcc/cp/cp-gimplify.c	2010-12-13 17:46:05.000000000 +0100
@@ -958,6 +958,23 @@  cp_genericize (tree fndecl)
       DECL_BY_REFERENCE (t) = 1;
       TREE_ADDRESSABLE (t) = 0;
       relayout_decl (t);
+      if (DECL_NAME (t))
+	{
+	  /* Adjust DECL_VALUE_EXPR of the original var.  */
+	  tree outer = outer_curly_brace_block (current_function_decl);
+	  tree var;
+
+	  if (outer)
+	    for (var = BLOCK_VARS (outer); var; var = DECL_CHAIN (var))
+	      if (DECL_NAME (t) == DECL_NAME (var)
+		  && DECL_HAS_VALUE_EXPR_P (var)
+		  && DECL_VALUE_EXPR (var) == t)
+		{
+		  tree val = convert_from_reference (t);
+		  SET_DECL_VALUE_EXPR (var, val);
+		  break;
+		}
+	}
     }
 
   /* If we're a clone, the body is already GIMPLE.  */
--- gcc/testsuite/g++.dg/guality/pr46815.C.jj	2010-12-13 17:41:19.000000000 +0100
+++ gcc/testsuite/g++.dg/guality/pr46815.C	2010-12-13 17:45:04.000000000 +0100
@@ -0,0 +1,25 @@ 
+// PR debug/46815
+// { dg-do run }
+// { dg-options "-g" }
+// { dg-skip-if "" { *-*-* }  { "*" } { "-O0" } }
+
+struct S
+{
+  int i;
+  S () { i = 42; }
+  virtual void foo (void) {}
+};
+
+S
+bar ()
+{
+  S s;
+  return s;	// { dg-final { gdb-test 17 "s.i" "42" } }
+}
+
+int
+main ()
+{
+  S s = bar ();
+  return s.i - 42;
+}