aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-03-04 12:59:04 +0100
committerJakub Jelinek <jakub@redhat.com>2020-03-04 12:59:04 +0100
commit64ba6d17022eeb65f56f0b141c2640f9ab938f97 (patch)
tree0c1fd44a3b5ba8341466c911d0a924dc07d53a1f
parent1cdfb80a4ec7b6585b436917e13b205055732232 (diff)
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.
-rw-r--r--gcc/ChangeLog3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/guality/pr93888.C24
-rw-r--r--gcc/tree-inline.c1
4 files changed, 33 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index df70632a763..b32bd446a45 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,8 @@
2020-03-04 Jakub Jelinek <jakub@redhat.com>
+ PR debug/93888
+ * tree-inline.c (copy_decl_to_var): Copy DECL_BY_REFERENCE flag.
+
* tree-ssa-sccvn.c (vn_walk_cb_data::push_partial_def): Add offseti
argument. Change pd argument so that it can be modified. Turn
constant non-CONSTRUCTOR store into non-constant if it is too large.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cbf17163195..90061eee337 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR debug/93888
+ * g++.dg/guality/pr93888.C: New test.
+
2020-02-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/93964
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 23941dade55..59798ec0454 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -5929,6 +5929,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);
}