public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR55641] drop spurious const_type from reference_type variables
@ 2016-08-02  3:21 Alexandre Oliva
  2016-08-04 16:13 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2016-08-02  3:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, ccoutant

Although C++ reference types, denoted by DW_TAG_reference_type in
DWARFv2+ debug info, are unchangeable, we output names of reference type
with DW_TAG_const_type, because internally we mark such variables as
TREE_READONLY.  That's an internal implementation detail that shouldn't
leak to debug information.  This patch fixes this.

The testcase is slightly changed from the one attached to the bug
report, so that it runs in C++98 mode too.

Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?

for  gcc/ChangeLog

	PR debug/55641
	* dwarf2out.c (decl_quals): Don't map TREE_READONLY to
	TYPE_QUAL_CONST in reference-typed decls.

for  gcc/testsuite/ChangeLog

	PR debug/55641
	* g++.dg/debug/dwarf2/ref-1.C: New.
---
 gcc/dwarf2out.c                           |    4 ++++
 gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C |   19 +++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 8d6eeed..103095f 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -11135,6 +11135,10 @@ static int
 decl_quals (const_tree decl)
 {
   return ((TREE_READONLY (decl)
+	   /* The C++ front-end correctly marks reference-typed
+	      variables as readonly, but from a language (and debug
+	      info) standpoint they are not const-qualified.  */
+	   && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
 	   ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
 	  | (TREE_THIS_VOLATILE (decl)
 	     ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C
new file mode 100644
index 0000000..75e9fca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-O -g -dA -gno-strict-dwarf" }
+// { dg-final { scan-assembler-not "DW_TAG_const_type" { xfail { powerpc-ibm-aix* } } } }
+
+int x;
+int &y = x;
+
+typedef int &z_t;
+z_t z = x;
+
+void f(int &p) {}
+
+struct foo {
+  int &bar;
+  typedef int &bart;
+  bart fool;
+};
+
+void f3(struct foo &p) {}

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PR55641] drop spurious const_type from reference_type variables
  2016-08-02  3:21 [PR55641] drop spurious const_type from reference_type variables Alexandre Oliva
@ 2016-08-04 16:13 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-08-04 16:13 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches List, ccoutant

OK.

On Mon, Aug 1, 2016 at 11:12 PM, Alexandre Oliva <aoliva@redhat.com> wrote:
> Although C++ reference types, denoted by DW_TAG_reference_type in
> DWARFv2+ debug info, are unchangeable, we output names of reference type
> with DW_TAG_const_type, because internally we mark such variables as
> TREE_READONLY.  That's an internal implementation detail that shouldn't
> leak to debug information.  This patch fixes this.
>
> The testcase is slightly changed from the one attached to the bug
> report, so that it runs in C++98 mode too.
>
> Regstrapped on x86_64-linux-gnu and i686-linux-gnu.  Ok to install?
>
> for  gcc/ChangeLog
>
>         PR debug/55641
>         * dwarf2out.c (decl_quals): Don't map TREE_READONLY to
>         TYPE_QUAL_CONST in reference-typed decls.
>
> for  gcc/testsuite/ChangeLog
>
>         PR debug/55641
>         * g++.dg/debug/dwarf2/ref-1.C: New.
> ---
>  gcc/dwarf2out.c                           |    4 ++++
>  gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C |   19 +++++++++++++++++++
>  2 files changed, 23 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C
>
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 8d6eeed..103095f 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -11135,6 +11135,10 @@ static int
>  decl_quals (const_tree decl)
>  {
>    return ((TREE_READONLY (decl)
> +          /* The C++ front-end correctly marks reference-typed
> +             variables as readonly, but from a language (and debug
> +             info) standpoint they are not const-qualified.  */
> +          && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE
>            ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED)
>           | (TREE_THIS_VOLATILE (decl)
>              ? TYPE_QUAL_VOLATILE : TYPE_UNQUALIFIED));
> diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C
> new file mode 100644
> index 0000000..75e9fca
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C
> @@ -0,0 +1,19 @@
> +// { dg-do compile }
> +// { dg-options "-O -g -dA -gno-strict-dwarf" }
> +// { dg-final { scan-assembler-not "DW_TAG_const_type" { xfail { powerpc-ibm-aix* } } } }
> +
> +int x;
> +int &y = x;
> +
> +typedef int &z_t;
> +z_t z = x;
> +
> +void f(int &p) {}
> +
> +struct foo {
> +  int &bar;
> +  typedef int &bart;
> +  bart fool;
> +};
> +
> +void f3(struct foo &p) {}
>
> --
> Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
> You must be the change you wish to see in the world. -- Gandhi
> Be Free! -- http://FSFLA.org/   FSF Latin America board member
> Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-04 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-02  3:21 [PR55641] drop spurious const_type from reference_type variables Alexandre Oliva
2016-08-04 16:13 ` Jason Merrill

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