]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport "[c++] Fix DECL_BY_REFERENCE of clone parms"
authorTom de Vries <tdevries@suse.de>
Tue, 23 Oct 2018 17:16:55 +0000 (17:16 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Tue, 23 Oct 2018 17:16:55 +0000 (17:16 +0000)
Consider test.C compiled at -O0 -g:
...
class string {
public:
  string (const char *p) { this->p = p ; }
  string (const string &s) { this->p = s.p; }

private:
  const char *p;
};

class foo {
public:
  foo (string dir_hint) {}
};

int
main (void)
{
  std::string s = "This is just a string";
  foo bar(s);
  return 0;
}
...

When parsing foo::foo, the dir_hint parameter gets a DECL_ARG_TYPE of
'struct string & restrict'.  Then during finish_struct, we call
clone_constructors_and_destructors and create clones for foo::foo, and
set the DECL_ARG_TYPE in the same way.

Later on, during finish_function, cp_genericize is called for the original
foo::foo, which sets the type of parm dir_hint to DECL_ARG_TYPE, and sets
DECL_BY_REFERENCE of dir_hint to 1.

After that, during maybe_clone_body update_cloned_parm is called with:
...
(gdb) call debug_generic_expr (parm.typed.type)
struct string & restrict
(gdb) call debug_generic_expr (cloned_parm.typed.type)
struct string
...
The type of the cloned_parm is then set to the type of parm, but
DECL_BY_REFERENCE is not set.

When doing cp_genericize for the clone later on,
TREE_ADDRESSABLE (TREE_TYPE ()) is no longer true for the updated type for
the parm, so DECL_BY_REFERENCE is not set there either.

The missing DECL_BY_REFERENCE on cloned_parm causes incorrect debug info to be
generated.

This patch fixes the problem by copying DECL_BY_REFERENCE in update_cloned_parm.

Bootstrapped and reg-tested on x86_64.

2018-10-23  Tom de Vries  <tdevries@suse.de>

backport from trunk:
2018-07-31  Tom de Vries  <tdevries@suse.de>

PR debug/86687
* optimize.c (update_cloned_parm): Copy DECL_BY_REFERENCE.

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

From-SVN: r265431

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

index 800856077a2f8019d3d5a1d39f9837f352839c37..efd6b0ba586189caec804ff630f3db68552abacd 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-23  Tom de Vries  <tdevries@suse.de>
+
+       backport from trunk:
+       2018-07-31  Tom de Vries  <tdevries@suse.de>
+
+       PR debug/86687
+       * optimize.c (update_cloned_parm): Copy DECL_BY_REFERENCE.
+
 2018-10-12  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 6f80b3d6d842c8616477391bf8c0d3775ef101b8..e7bfc7614ea113fdf408e808175f08c99b73c907 100644 (file)
@@ -46,6 +46,8 @@ update_cloned_parm (tree parm, tree cloned_parm, bool first)
   /* We may have taken its address.  */
   TREE_ADDRESSABLE (cloned_parm) = TREE_ADDRESSABLE (parm);
 
+  DECL_BY_REFERENCE (cloned_parm) = DECL_BY_REFERENCE (parm);
+
   /* The definition might have different constness.  */
   TREE_READONLY (cloned_parm) = TREE_READONLY (parm);
 
index 51daecf179f820471ea7f8f049e0ce0c1c6a2b5d..70fcb9c4c69d3f5a5647967fce0415016201ec96 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-23  Tom de Vries  <tdevries@suse.de>
+
+       backport from trunk:
+       2018-07-31  Tom de Vries  <tdevries@suse.de>
+
+       PR debug/86687
+       * g++.dg/guality/pr86687.C: New test.
+
 2018-10-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c-torture/execute/pr87623.c: New test.
diff --git a/gcc/testsuite/g++.dg/guality/pr86687.C b/gcc/testsuite/g++.dg/guality/pr86687.C
new file mode 100644 (file)
index 0000000..b2cdaf8
--- /dev/null
@@ -0,0 +1,28 @@
+// PR debug/86687
+// { dg-do run }
+// { dg-options "-g" }
+
+class string {
+public:
+  string (int p) { this->p = p ; }
+  string (const string &s) { this->p = s.p; }
+
+  int p;
+};
+
+class foo {
+public:
+  foo (string dir_hint) {
+    p = dir_hint.p; // { dg-final { gdb-test 16 "dir_hint.p" 3 } }
+  }
+
+  int p;
+};
+
+int
+main (void)
+{
+  string s = 3;
+  foo bar(s);
+  return !(bar.p == 3);
+}