public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-9-branch)] inliner: Copy DECL_BY_REFERENCE in copy_decl_to_var [PR93888]
@ 2020-03-17 19:24 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-03-17 19:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d2a810ee83e2952bf351498cecf8f5db28860a24

commit d2a810ee83e2952bf351498cecf8f5db28860a24
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 4 12:59:04 2020 +0100

    inliner: Copy DECL_BY_REFERENCE in copy_decl_to_var [PR93888]
    
    In the following testcase we emit wrong debug info for the karg
    parameter in the DW_TAG_inlined_subroutine into main.
    The problem is that the karg PARM_DECL is DECL_BY_REFERENCE and thus
    in the IL has const K & type, but in the source just const K.
    When the function is inlined, we create a VAR_DECL for it, but don't
    set DECL_BY_REFERENCE, so when emitting DW_AT_location, we treat it like
    a const K & typed variable, but it has DW_AT_abstract_origin which has
    just the const K type and thus the debugger thinks the variable has
    const K type.
    
    Fixed by copying the DECL_BY_REFERENCE flag.  Not doing it in
    copy_decl_for_dup_finish, because copy_decl_no_change already copies
    that flag through copy_node and in copy_result_decl_to_var it is
    undesirable, as we handle DECL_BY_REFERENCE in that case instead
    by changing the type.
    
    2020-03-04  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/93888
            * tree-inline.c (copy_decl_to_var): Copy DECL_BY_REFERENCE flag.
    
            * g++.dg/guality/pr93888.C: New test.

Diff:
---
 gcc/ChangeLog                          |  3 +++
 gcc/testsuite/ChangeLog                |  3 +++
 gcc/testsuite/g++.dg/guality/pr93888.C | 24 ++++++++++++++++++++++++
 gcc/tree-inline.c                      |  1 +
 4 files changed, 31 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3e93b3ae62b..4b81a55064a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2020-03-04  Jakub Jelinek  <jakub@redhat.com>
 
+	PR debug/93888
+	* tree-inline.c (copy_decl_to_var): Copy DECL_BY_REFERENCE flag.
+
 	PR tree-optimization/94001
 	* tree-tailcall.c (process_assignment): Before comparing op1 to
 	*ass_var, verify *ass_var is non-NULL.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bbc3bef437f..edce0bec2bb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2020-03-04  Jakub Jelinek  <jakub@redhat.com>
 
+	PR debug/93888
+	* g++.dg/guality/pr93888.C: New test.
+
 	PR tree-optimization/94001
 	* gcc.dg/pr94001.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/guality/pr93888.C b/gcc/testsuite/g++.dg/guality/pr93888.C
new file mode 100644
index 00000000000..d54a4dcc8cc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/guality/pr93888.C
@@ -0,0 +1,24 @@
+// PR debug/93888
+// { dg-do run }
+// { dg-options "-g -fvar-tracking -fno-inline" }
+// { dg-skip-if "" { *-*-* }  { "*" } { "-O0" } }
+
+struct K
+{
+  K () {}
+  K (K const &rhs) { k[0] = 'C'; }
+  char k[8] = {'B','B','B','B','B','B','B','B'};
+};
+
+__attribute__((always_inline)) inline bool
+foo (const K karg)
+{
+  return karg.k[0] != 'C';	// { dg-final { gdb-test 16 "karg.k[0]" "'C'" } }
+}				// { dg-final { gdb-test 16 "karg.k[1]" "'B'" } }
+
+int
+main ()
+{
+  K x;
+  return foo (x);
+}
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index d115fcb1a5b..7ba2ebf3695 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -5698,6 +5698,7 @@ copy_decl_to_var (tree decl, copy_body_data *id)
   TREE_READONLY (copy) = TREE_READONLY (decl);
   TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
   DECL_GIMPLE_REG_P (copy) = DECL_GIMPLE_REG_P (decl);
+  DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl);
 
   return copy_decl_for_dup_finish (id, decl, copy);
 }


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

only message in thread, other threads:[~2020-03-17 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 19:24 [gcc(refs/vendors/redhat/heads/gcc-9-branch)] inliner: Copy DECL_BY_REFERENCE in copy_decl_to_var [PR93888] Jakub Jelinek

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).