dwarf2out.c (gen_variable_die): For -gdwarf-5...
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Feb 2017 21:33:47 +0000 (22:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 22 Feb 2017 21:33:47 +0000 (22:33 +0100)
* dwarf2out.c (gen_variable_die): For -gdwarf-5, use DW_TAG_variable
instead of DW_TAG_member for static data member declarations and don't
set no_linkage_name for static inline data members.
(gen_member_die): For -gdwarf-5 don't change DW_TAG_variable
to DW_TAG_member.

* g++.dg/debug/dwarf2/inline-var-2.C: New test.

From-SVN: r245661

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

index fc21097829c43490387eed1e52c7c9aa60ba2188..f6168c93a540a41b47e715a0b8cd2626285d9f07 100644 (file)
@@ -1,3 +1,11 @@
+2017-02-22  Jakub Jelinek  <jakub@redhat.com>
+
+       * dwarf2out.c (gen_variable_die): For -gdwarf-5, use DW_TAG_variable
+       instead of DW_TAG_member for static data member declarations and don't
+       set no_linkage_name for static inline data members.
+       (gen_member_die): For -gdwarf-5 don't change DW_TAG_variable
+       to DW_TAG_member.
+
 2017-02-22  Martin Liska  <mliska@suse.cz>
 
        * doc/invoke.texi: Replace inequality signs with square brackets
index 14c14f3c9ec72aefde5b5f58d942b1f5fbe4b4d7..541d86824bdcd96c93e6495f8964a931596384d3 100644 (file)
@@ -22669,7 +22669,8 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
       && lang_hooks.decls.decl_dwarf_attribute (decl, DW_AT_inline) != -1)
     {
       declaration = true;
-      no_linkage_name = true;
+      if (dwarf_version < 5)
+       no_linkage_name = true;
     }
 
   ultimate_origin = decl_ultimate_origin (decl_or_origin);
@@ -22820,9 +22821,10 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
     }
 
   /* For static data members, the declaration in the class is supposed
-     to have DW_TAG_member tag; the specification should still be
-     DW_TAG_variable referencing the DW_TAG_member DIE.  */
-  if (declaration && class_scope_p (context_die))
+     to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility
+     also in DWARF2; the specification should still be DW_TAG_variable
+     referencing the DW_TAG_member DIE.  */
+  if (declaration && class_scope_p (context_die) && dwarf_version < 5)
     var_die = new_die (DW_TAG_member, context_die, decl);
   else
     var_die = new_die (DW_TAG_variable, context_die, decl);
@@ -24091,7 +24093,8 @@ gen_member_die (tree type, dw_die_ref context_die)
              && get_AT (child, DW_AT_specification) == NULL)
            {
              reparent_child (child, context_die);
-             child->die_tag = DW_TAG_member;
+             if (dwarf_version < 5)
+               child->die_tag = DW_TAG_member;
            }
          else
            splice_child_die (context_die, child);
@@ -24113,7 +24116,7 @@ gen_member_die (tree type, dw_die_ref context_die)
        }
 
       /* For C++ inline static data members emit immediately a DW_TAG_variable
-        DIE that will refer to that DW_TAG_member through
+        DIE that will refer to that DW_TAG_member/DW_TAG_variable through
         DW_AT_specification.  */
       if (TREE_STATIC (member)
          && (lang_hooks.decls.decl_dwarf_attribute (member, DW_AT_inline)
index 6fae11a52e5e4517b3d8953a77ec9b9087afc234..c5f757635d2aa1761677fbbef0aaefc52bffb62e 100644 (file)
@@ -1,3 +1,7 @@
+2017-02-22  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.dg/debug/dwarf2/inline-var-2.C: New test.
+
 2017-02-22  Marek Polacek  <polacek@redhat.com>
 
        PR c++/79653
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-var-2.C
new file mode 100644 (file)
index 0000000..d04bbd6
--- /dev/null
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-O -std=c++1z -gdwarf-5 -dA -gno-strict-dwarf" }
+// { dg-require-weak "" }
+// { dg-final { scan-assembler-not "DW_TAG_member" { xfail *-*-aix* } } }
+
+inline int a;
+struct S
+{
+  static inline double b = 4.0;
+  static constexpr int c = 2;
+  static constexpr inline char d = 3;
+  static const int j = 7;
+  static int k;
+  static double l;
+} s;
+const int S::j;
+int S::k = 8;
+template <int N>
+inline int e = N;
+int &f = e<2>;
+template <int N>
+struct T
+{
+  static inline double g = 4.0;
+  static constexpr int h = 2;
+  static inline constexpr char i = 3;
+  static const int m = 8;
+  static int n;
+  static double o;
+};
+T<5> t;
+template <>
+const int T<5>::m;
+template <>
+int T<5>::n = 9;