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

Jakub Jelinek jakub@redhat.com
Tue Dec 14 09:50:00 GMT 2010


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.

--- 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;
+}

	Jakub



More information about the Gcc-patches mailing list