debug.h (struct gcc_debug_hooks): Add IMPLICIT argument to imported_module_or_decl...
authorJakub Jelinek <jakub@redhat.com>
Sat, 29 Jul 2017 07:52:16 +0000 (09:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 29 Jul 2017 07:52:16 +0000 (09:52 +0200)
* debug.h (struct gcc_debug_hooks): Add IMPLICIT argument
to imported_module_or_decl hook.
(debug_nothing_tree_tree_tree_bool): Remove.
(debug_nothing_tree_tree_tree_bool_bool): New declaration.
* debug.c (do_nothing_debug_hooks): Use
debug_nothing_tree_tree_tree_bool_bool instead of
debug_nothing_tree_tree_tree_bool.
* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
* dbxout.c (dbx_debug_hooks, xcoff_debug_hooks): Likewise.
* sdbout.c (sdb_debug_hooks): Likewise.
* dwarf2out.c (dwarf2_lineno_debug_hooks): Likewise.
(gen_namespace_die): Add DW_AT_export_symbols attribute if
langhook wants it.
(dwarf2out_imported_module_or_decl): Add IMPLICIT argument,
if true, -gdwarf-5 and decl will have DW_AT_export_symbols
attribute, don't add anything.
cp/
* cp-objcp-common.c (cp_decl_dwarf_attribute): Handle
DW_AT_export_symbols.
* name-lookup.c (emit_debug_info_using_namespace): Add IMPLICIT
argument, pass it through to the debug hook.
(finish_namespace_using_directive): Adjust
emit_debug_info_using_namespace caller.
(push_namespace): Likewise.  Call it after setting
DECL_NAMESPACE_INLINE_P.
(cp_emit_debug_info_for_using): Pass false as new argument to
the imported_module_or_decl debug hook.
fortran/
* trans-decl.c (gfc_trans_use_stmts): Pass false as new argument to
the imported_module_or_decl debug hook.
ada/
* gcc-interface/utils.c (gnat_write_global_declarations): Pass false
as new argument to the imported_module_or_decl debug hook.
testsuite/
* g++.dg/debug/dwarf2/inline-ns-1.C: New test.
* g++.dg/debug/dwarf2/inline-ns-2.C: New test.

From-SVN: r250713

17 files changed:
gcc/ChangeLog
gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils.c
gcc/cp/ChangeLog
gcc/cp/cp-objcp-common.c
gcc/cp/name-lookup.c
gcc/dbxout.c
gcc/debug.c
gcc/debug.h
gcc/dwarf2out.c
gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/sdbout.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-2.C [new file with mode: 0644]
gcc/vmsdbgout.c

index 2aafa710294e67ba37b1104c5010d062fa053392..ad347ad9754f8797cdc2c0b35a39522c4db62498 100644 (file)
@@ -1,3 +1,22 @@
+2017-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * debug.h (struct gcc_debug_hooks): Add IMPLICIT argument
+       to imported_module_or_decl hook.
+       (debug_nothing_tree_tree_tree_bool): Remove.
+       (debug_nothing_tree_tree_tree_bool_bool): New declaration.
+       * debug.c (do_nothing_debug_hooks): Use
+       debug_nothing_tree_tree_tree_bool_bool instead of
+       debug_nothing_tree_tree_tree_bool.
+       * vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
+       * dbxout.c (dbx_debug_hooks, xcoff_debug_hooks): Likewise.
+       * sdbout.c (sdb_debug_hooks): Likewise.
+       * dwarf2out.c (dwarf2_lineno_debug_hooks): Likewise.
+       (gen_namespace_die): Add DW_AT_export_symbols attribute if
+       langhook wants it.
+       (dwarf2out_imported_module_or_decl): Add IMPLICIT argument,
+       if true, -gdwarf-5 and decl will have DW_AT_export_symbols
+       attribute, don't add anything.
+
 2017-07-28  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
 
        * fold-const.c (fold_build1_stat_loc): Remove _stat from name.
index 3daed1e1f35612ac5bb90360ee1fcb71df6cbcc2..dda51d423b633a605bdf1a8a731454cd76b4183b 100644 (file)
@@ -1,3 +1,8 @@
+2017-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc-interface/utils.c (gnat_write_global_declarations): Pass false
+       as new argument to the imported_module_or_decl debug hook.
+
 2017-07-25  Javier Miranda  <miranda@adacore.com>
 
        * checks.adb (Apply_Divide_Checks): Ensure that operands are not
index 9e656579dda2203a1bb8d6152c4cbf3c99606711..475261b36828db5348c2b7f22789b3447da56d48 100644 (file)
@@ -5553,7 +5553,7 @@ gnat_write_global_declarations (void)
   FOR_EACH_VEC_SAFE_ELT (global_decls, i, iter)
    if (TREE_CODE (iter) == IMPORTED_DECL && !DECL_IGNORED_P (iter))
      debug_hooks->imported_module_or_decl (iter, DECL_NAME (iter),
-                                          DECL_CONTEXT (iter), 0);
+                                          DECL_CONTEXT (iter), false, false);
 }
 
 /* ************************************************************************
index 806235fcd75353e2a29e394e3c282bbab1d98e8c..3d988a67b7757075b3a8fadffd76bc46308eeafb 100644 (file)
@@ -1,3 +1,16 @@
+2017-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * cp-objcp-common.c (cp_decl_dwarf_attribute): Handle
+       DW_AT_export_symbols.
+       * name-lookup.c (emit_debug_info_using_namespace): Add IMPLICIT
+       argument, pass it through to the debug hook.
+       (finish_namespace_using_directive): Adjust
+       emit_debug_info_using_namespace caller.
+       (push_namespace): Likewise.  Call it after setting
+       DECL_NAMESPACE_INLINE_P.
+       (cp_emit_debug_info_for_using): Pass false as new argument to
+       the imported_module_or_decl debug hook.
+
 2017-07-28  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
 
        * lex.c (copy_decl): Adjust.
index 5a7da5b495713780fb24cdf817a0ddb865f7202c..4475b6cb911357773961aea08c96a542d024eb00 100644 (file)
@@ -212,6 +212,13 @@ cp_decl_dwarf_attribute (const_tree decl, int attr)
        }
       break;
 
+    case DW_AT_export_symbols:
+      if (TREE_CODE (decl) == NAMESPACE_DECL
+         && (DECL_NAMESPACE_INLINE_P (decl)
+             || (DECL_NAME (decl) == NULL_TREE && dwarf_version >= 5)))
+       return 1;
+      break;
+
     default:
       break;
     }
index cd7428a4ea4cb663bdef97d1116ccb7d706aa975..4dc19da6ade795470ba92bf60784ab482ab00845 100644 (file)
@@ -6045,11 +6045,12 @@ add_using_namespace (vec<tree, va_gc> *&usings, tree target)
 /* Tell the debug system of a using directive.  */
 
 static void
-emit_debug_info_using_namespace (tree from, tree target)
+emit_debug_info_using_namespace (tree from, tree target, bool implicit)
 {
   /* Emit debugging info.  */
   tree context = from != global_namespace ? from : NULL_TREE;
-  debug_hooks->imported_module_or_decl (target, NULL_TREE, context, false);
+  debug_hooks->imported_module_or_decl (target, NULL_TREE, context, false,
+                                       implicit);
 }
 
 /* Process a namespace-scope using directive.  */
@@ -6064,7 +6065,7 @@ finish_namespace_using_directive (tree target, tree attribs)
   add_using_namespace (DECL_NAMESPACE_USING (current_namespace),
                       ORIGINAL_NAMESPACE (target));
   emit_debug_info_using_namespace (current_namespace,
-                                  ORIGINAL_NAMESPACE (target));
+                                  ORIGINAL_NAMESPACE (target), false);
 
   if (attribs == error_mark_node)
     return;
@@ -6223,14 +6224,14 @@ push_namespace (tree name, bool make_inline)
          else if (TREE_PUBLIC (current_namespace))
            TREE_PUBLIC (ns) = 1;
 
-         if (name == anon_identifier || make_inline)
-           emit_debug_info_using_namespace (current_namespace, ns);
-
          if (make_inline)
            {
              DECL_NAMESPACE_INLINE_P (ns) = true;
              vec_safe_push (DECL_NAMESPACE_INLINEES (current_namespace), ns);
            }
+
+         if (name == anon_identifier || make_inline)
+           emit_debug_info_using_namespace (current_namespace, ns, true);
        }
     }
 
@@ -6358,8 +6359,8 @@ cp_emit_debug_info_for_using (tree t, tree context)
          if (building_stmt_list_p ())
            add_stmt (build_stmt (input_location, USING_STMT, fn));
          else
-           debug_hooks->imported_module_or_decl (fn,
-                                                 NULL_TREE, context, false);
+           debug_hooks->imported_module_or_decl (fn, NULL_TREE, context,
+                                                 false, false);
        }
     }
 }
index b278c6da1d4405ee8dcc4c718bdc7884b29ebe15..3d9268c3d1d725fa8594603a72431e412bdadf24 100644 (file)
@@ -371,7 +371,7 @@ const struct gcc_debug_hooks dbx_debug_hooks =
   dbxout_early_global_decl,             /* early_global_decl */
   dbxout_late_global_decl,              /* late_global_decl */
   dbxout_type_decl,                     /* type_decl */
-  debug_nothing_tree_tree_tree_bool,    /* imported_module_or_decl */
+  debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
   debug_nothing_tree,                   /* deferred_inline_function */
   debug_nothing_tree,                   /* outlining_inline_function */
   debug_nothing_rtx_code_label,                 /* label */
@@ -411,7 +411,7 @@ const struct gcc_debug_hooks xcoff_debug_hooks =
   dbxout_early_global_decl,             /* early_global_decl */
   dbxout_late_global_decl,              /* late_global_decl */
   dbxout_type_decl,                     /* type_decl */
-  debug_nothing_tree_tree_tree_bool,    /* imported_module_or_decl */
+  debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
   debug_nothing_tree,                   /* deferred_inline_function */
   debug_nothing_tree,                   /* outlining_inline_function */
   debug_nothing_rtx_code_label,                 /* label */
index 860f1e312b995567e9ba4e9ab31ba180fcaa04a9..d68c30ff2b9a7d90be1759eae5647c693c898ca5 100644 (file)
@@ -47,7 +47,7 @@ const struct gcc_debug_hooks do_nothing_debug_hooks =
   debug_nothing_tree,                   /* early_global_decl */
   debug_nothing_tree,                   /* late_global_decl */
   debug_nothing_tree_int,               /* type_decl */
-  debug_nothing_tree_tree_tree_bool,    /* imported_module_or_decl */
+  debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
   debug_nothing_tree,                   /* deferred_inline_function */
   debug_nothing_tree,                   /* outlining_inline_function */
   debug_nothing_rtx_code_label,                 /* label */
@@ -80,10 +80,11 @@ debug_nothing_tree_tree (tree t1 ATTRIBUTE_UNUSED,
 }
 
 void
-debug_nothing_tree_tree_tree_bool (tree t1 ATTRIBUTE_UNUSED,
-                                  tree t2 ATTRIBUTE_UNUSED,
-                                  tree t3 ATTRIBUTE_UNUSED,
-                                  bool b1 ATTRIBUTE_UNUSED)
+debug_nothing_tree_tree_tree_bool_bool (tree t1 ATTRIBUTE_UNUSED,
+                                       tree t2 ATTRIBUTE_UNUSED,
+                                       tree t3 ATTRIBUTE_UNUSED,
+                                       bool b1 ATTRIBUTE_UNUSED,
+                                       bool b2 ATTRIBUTE_UNUSED)
 {
 }
 
index 395365861f78a3845710e81679d483d60ab504b5..bfb72213631a0c6bd27eaf5cfaed7ae24b8c977e 100644 (file)
@@ -145,7 +145,8 @@ struct gcc_debug_hooks
 
   /* Debug information for imported modules and declarations.  */
   void (* imported_module_or_decl) (tree decl, tree name,
-                                   tree context, bool child);
+                                   tree context, bool child,
+                                   bool implicit);
 
   /* DECL is an inline function, whose body is present, but which is
      not being output at this point.  */
@@ -206,7 +207,8 @@ extern void debug_nothing_int_int (unsigned int, unsigned int);
 extern void debug_nothing_tree (tree);
 extern void debug_nothing_tree_tree (tree, tree);
 extern void debug_nothing_tree_int (tree, int);
-extern void debug_nothing_tree_tree_tree_bool (tree, tree, tree, bool);
+extern void debug_nothing_tree_tree_tree_bool_bool (tree, tree, tree,
+                                                   bool, bool);
 extern bool debug_true_const_tree (const_tree);
 extern void debug_nothing_rtx_insn (rtx_insn *);
 extern void debug_nothing_rtx_code_label (rtx_code_label *);
index 5231683ee9e2b01354d2256d40feaf70c8d1a5c1..4a3b3c1d0f494986c6d3f5c8e522dc7d53e61999 100644 (file)
@@ -2680,7 +2680,7 @@ static bool dwarf2out_ignore_block (const_tree);
 static void dwarf2out_early_global_decl (tree);
 static void dwarf2out_late_global_decl (tree);
 static void dwarf2out_type_decl (tree, int);
-static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
+static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool, bool);
 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
                                                 dw_die_ref);
 static void dwarf2out_abstract_function (tree);
@@ -2764,7 +2764,7 @@ const struct gcc_debug_hooks dwarf2_lineno_debug_hooks =
   debug_nothing_tree,                   /* early_global_decl */
   debug_nothing_tree,                   /* late_global_decl */
   debug_nothing_tree_int,               /* type_decl */
-  debug_nothing_tree_tree_tree_bool,    /* imported_module_or_decl */
+  debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
   debug_nothing_tree,                   /* deferred_inline_function */
   debug_nothing_tree,                   /* outlining_inline_function */
   debug_nothing_rtx_code_label,                 /* label */
@@ -25166,6 +25166,11 @@ gen_namespace_die (tree decl, dw_die_ref context_die)
       add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
       equate_decl_number_to_die (decl, namespace_die);
     }
+  if ((dwarf_version >= 5 || !dwarf_strict)
+      && lang_hooks.decls.decl_dwarf_attribute (decl,
+                                               DW_AT_export_symbols) == 1)
+    add_AT_flag (namespace_die, DW_AT_export_symbols, 1);
+
   /* Bypass dwarf2_name's check for DECL_NAMELESS.  */
   if (want_pubnames ())
     add_pubname_string (lang_hooks.dwarf_name (decl, 1), namespace_die);
@@ -25579,11 +25584,13 @@ dwarf2out_imported_module_or_decl_1 (tree decl,
 /* Output debug information for imported module or decl DECL.
    NAME is non-NULL name in context if the decl has been renamed.
    CHILD is true if decl is one of the renamed decls as part of
-   importing whole module.  */
+   importing whole module.
+   IMPLICIT is set if this hook is called for an implicit import
+   such as inline namespace.  */
 
 static void
 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
-                                  bool child)
+                                  bool child, bool implicit)
 {
   /* dw_die_ref at_import_die;  */
   dw_die_ref scope_die;
@@ -25593,6 +25600,16 @@ dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
 
   gcc_assert (decl);
 
+  /* For DWARF5, just DW_AT_export_symbols on the DW_TAG_namespace
+     should be enough, for DWARF4 and older even if we emit as extension
+     DW_AT_export_symbols add the implicit DW_TAG_imported_module anyway
+     for the benefit of consumers unaware of DW_AT_export_symbols.  */
+  if (implicit
+      && dwarf_version >= 5
+      && lang_hooks.decls.decl_dwarf_attribute (decl,
+                                               DW_AT_export_symbols) == 1)
+    return;
+
   set_early_dwarf s;
 
   /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
index 2b9aba6d8f723afeb05f589fbd300ec6364193f6..81b220ad776a3cdfd8aeff8d703625ee2d6d3f17 100644 (file)
@@ -1,3 +1,8 @@
+2017-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * trans-decl.c (gfc_trans_use_stmts): Pass false as new argument to
+       the imported_module_or_decl debug hook.
+
 2017-07-28  Trevor Saunders  <tbsaunde+gcc@tbsaunde.org>
 
        * resolve.c (find_reachable_labels): Adjust.
index b2f73b784663e1f52ae29cc5c75b18a32ee9576f..74d860689ee791f64b3369b555d21f20db553022 100644 (file)
@@ -4875,7 +4875,7 @@ gfc_trans_use_stmts (gfc_namespace * ns)
        (*debug_hooks->imported_module_or_decl) (entry->namespace_decl,
                                                 NULL_TREE,
                                                 ns->proc_name->backend_decl,
-                                                false);
+                                                false, false);
       for (rent = use_stmt->rename; rent; rent = rent->next)
        {
          tree decl, local_name;
@@ -4952,7 +4952,8 @@ gfc_trans_use_stmts (gfc_namespace * ns)
          gfc_set_backend_locus (&rent->where);
          (*debug_hooks->imported_module_or_decl) (decl, local_name,
                                                   ns->proc_name->backend_decl,
-                                                  !use_stmt->only_flag);
+                                                  !use_stmt->only_flag,
+                                                  false);
        }
     }
 }
index 84798ac9fb3eb1cbe539c0764c92e1db34954c59..a67f9d64cb16911a31372d4af44ba73a7f134ee9 100644 (file)
@@ -301,7 +301,7 @@ const struct gcc_debug_hooks sdb_debug_hooks =
   sdbout_early_global_decl,             /* early_global_decl */
   sdbout_late_global_decl,              /* late_global_decl */
   sdbout_symbol,                        /* type_decl */
-  debug_nothing_tree_tree_tree_bool,    /* imported_module_or_decl */
+  debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
   debug_nothing_tree,                   /* deferred_inline_function */
   debug_nothing_tree,                   /* outlining_inline_function */
   sdbout_label,                                 /* label */
index d2682dc70944c10607d5f8d247fac3f291fdda36..8e83a732a5f50fd5434e4052781e3280f03f76ab 100644 (file)
@@ -1,3 +1,8 @@
+2017-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.dg/debug/dwarf2/inline-ns-1.C: New test.
+       * g++.dg/debug/dwarf2/inline-ns-2.C: New test.
+
 2017-07-28  Peter Bergner  <bergner@vnet.ibm.com>
 
        * gcc.target/powerpc/cpu-builtin-1.c (darn, scv): Add tests.
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-1.C
new file mode 100644 (file)
index 0000000..cae380a
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-options "-O2 -gdwarf-4 -dA -gno-strict-dwarf" }
+// { dg-final { scan-assembler-times " DW_AT_export_symbols" 1 } }
+// { dg-final { scan-assembler-times "DIE \\(\[^\n\r\]*\\) DW_TAG_imported_module" 2 } }
+
+namespace A
+{
+  int i = 5;
+  inline namespace B
+  {
+    int j = 6;
+    namespace C
+    {
+      int k = 7;
+    };
+  };
+};
+int l = A::i + A::j + A::C::k;
+int m = A::i + A::B::j + A::B::C::k;
+namespace
+{
+  int n = 8;
+};
+int o = n;
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/inline-ns-2.C
new file mode 100644 (file)
index 0000000..4d9aed7
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-options "-O2 -gdwarf-5 -dA" }
+// { dg-final { scan-assembler-times " DW_AT_export_symbols" 2 } }
+// { dg-final { scan-assembler-not "DIE \\(\[^\n\r\]*\\) DW_TAG_imported_module" } }
+
+namespace A
+{
+  int i = 5;
+  inline namespace B
+  {
+    int j = 6;
+    namespace C
+    {
+      int k = 7;
+    };
+  };
+};
+int l = A::i + A::j + A::C::k;
+int m = A::i + A::B::j + A::B::C::k;
+namespace
+{
+  int n = 8;
+};
+int o = n;
index 41928a400a921434db0183764907f3e9a38cd3d6..42300e2d538c0ef68369cdb3e4c93cd661f2c064 100644 (file)
@@ -197,7 +197,7 @@ const struct gcc_debug_hooks vmsdbg_debug_hooks
    vmsdbgout_early_global_decl,
    vmsdbgout_late_global_decl,
    vmsdbgout_type_decl,                  /* type_decl */
-   debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
+   debug_nothing_tree_tree_tree_bool_bool, /* imported_module_or_decl */
    debug_nothing_tree,           /* deferred_inline_function */
    vmsdbgout_abstract_function,
    debug_nothing_rtx_code_label,  /* label */