[Bug debug/86687] Wrong debug information for string types passed as parameters

vries at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 23 17:17:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86687

--- Comment #17 from Tom de Vries <vries at gcc dot gnu.org> ---
Author: vries
Date: Tue Oct 23 17:16:55 2018
New Revision: 265431

URL: https://gcc.gnu.org/viewcvs?rev=265431&root=gcc&view=rev
Log:
backport "[c++] Fix DECL_BY_REFERENCE of clone parms"

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.

Added:
    branches/gcc-6-branch/gcc/testsuite/g++.dg/guality/pr86687.C
Modified:
    branches/gcc-6-branch/gcc/cp/ChangeLog
    branches/gcc-6-branch/gcc/cp/optimize.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog


More information about the Gcc-bugs mailing list