re PR debug/46815 (Invalid DW_AT_location for a retval instance of a class that has...
authorJakub Jelinek <jakub@redhat.com>
Wed, 15 Dec 2010 17:50:34 +0000 (18:50 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 15 Dec 2010 17:50:34 +0000 (18:50 +0100)
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.

From-SVN: r167865

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/guality/pr46815.C [new file with mode: 0644]

index 6dd121a91d6ab6a2670e0781de66b452aca2f702..b28af3c0c8ff8934b6eca89e63fa84c5f3dae57a 100644 (file)
@@ -1,3 +1,10 @@
+2010-12-15  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.
+
 2010-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/42083
index 42d7d58da370ffbbd0e8749a7b89000b482f8193..ca62df3e5858c7bd96bcd79e74c5142a3716babf 100644 (file)
@@ -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.  */
index 1d865c6dd91d18ca2eaa4c1066ccb69c6f229d22..a8cb558489490edb819c1693c5cc67eb259a6d2f 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/46815
+       * g++.dg/guality/pr46815.C: New test.
+
 2010-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/42083
diff --git a/gcc/testsuite/g++.dg/guality/pr46815.C b/gcc/testsuite/g++.dg/guality/pr46815.C
new file mode 100644 (file)
index 0000000..41b9219
--- /dev/null
@@ -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;
+}