[PR55641] drop spurious const_type from reference_type variables
authorAlexandre Oliva <aoliva@redhat.com>
Fri, 12 Aug 2016 07:11:36 +0000 (07:11 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Fri, 12 Aug 2016 07:11:36 +0000 (07:11 +0000)
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.

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.

From-SVN: r239402

gcc/ChangeLog
gcc/dwarf2out.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/dwarf2/ref-1.C [new file with mode: 0644]

index cdc5f290bef27f4db5dd2b4e99cc06d0e31aee8c..59e4fcf0eac8a6cd040dabc3d71f5f82732f6403 100644 (file)
@@ -1,5 +1,9 @@
 2016-08-12  Alexandre Oliva <aoliva@redhat.com>
 
+       PR debug/55641
+       * dwarf2out.c (decl_quals): Don't map TREE_READONLY to
+       TYPE_QUAL_CONST in reference-typed decls.
+
        PR debug/49366
        * dwarf2out.c (loc_list_from_tree_1): Expand some CONSTRUCTORs
        in DW_OP_pieces, just enough to handle pointers to member
index c658220c868cc5a9bee66f014d06f46ffcebfad0..06dbadbd15f95b97d0a85ae59a2ba91a33b7323c 100644 (file)
@@ -11126,6 +11126,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));
index 54939b8df3154bed264a10cebb49b4312394adce..1726157067ec6e59cbf969b2baead403dd1ad0ac 100644 (file)
@@ -1,5 +1,8 @@
 2016-08-12  Alexandre Oliva <aoliva@redhat.com>
 
+       PR debug/55641
+       * g++.dg/debug/dwarf2/ref-1.C: New.
+
        PR debug/49366
        * g++.dg/debug/dwarf2/template-params-12.H: New.
        * g++.dg/debug/dwarf2/template-params-12f.C: New.
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 (file)
index 0000000..75e9fca
--- /dev/null
@@ -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) {}