Blame SOURCES/gcc10-pr96383.patch

f03ecc
2020-07-30  Richard Biener  <rguenther@suse.de>
f03ecc
f03ecc
	PR debug/96383
f03ecc
	* langhooks-def.h (lhd_finalize_early_debug): Declare.
f03ecc
	(LANG_HOOKS_FINALIZE_EARLY_DEBUG): Define.
f03ecc
	(LANG_HOOKS_INITIALIZER): Amend.
f03ecc
	* langhooks.c: Include cgraph.h and debug.h.
f03ecc
	(lhd_finalize_early_debug): Default implementation from
f03ecc
	former code in finalize_compilation_unit.
f03ecc
	* langhooks.h (lang_hooks::finalize_early_debug): Add.
f03ecc
	* cgraphunit.c (symbol_table::finalize_compilation_unit):
f03ecc
	Call the finalize_early_debug langhook.
f03ecc
f03ecc
gcc/c-family/
f03ecc
	* c-common.h (c_common_finalize_early_debug): Declare.
f03ecc
	* c-common.c: Include debug.h.
f03ecc
	(c_common_finalize_early_debug): finalize_early_debug langhook
f03ecc
	implementation generating debug for extern declarations.
f03ecc
f03ecc
gcc/c/
f03ecc
	* c-objc-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG):
f03ecc
	Define to c_common_finalize_early_debug.
f03ecc
f03ecc
gcc/cp/
f03ecc
	* cp-objcp-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG):
f03ecc
	Define to c_common_finalize_early_debug.
f03ecc
f03ecc
gcc/testsuite/
f03ecc
	* gcc.dg/debug/dwarf2/pr96383-1.c: New testcase.
f03ecc
	* gcc.dg/debug/dwarf2/pr96383-2.c: Likewise.
f03ecc
f03ecc
libstdc++-v3/
f03ecc
	* testsuite/20_util/assume_aligned/3.cc: Use -g0.
f03ecc
f03ecc
--- gcc/c-family/c-common.c
f03ecc
+++ gcc/c-family/c-common.c
f03ecc
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
f03ecc
 #include "spellcheck.h"
f03ecc
 #include "c-spellcheck.h"
f03ecc
 #include "selftest.h"
f03ecc
+#include "debug.h"
f03ecc
 
f03ecc
 cpp_reader *parse_in;		/* Declared in c-pragma.h.  */
f03ecc
 
f03ecc
@@ -9086,4 +9087,20 @@ braced_lists_to_strings (tree type, tree ctor)
f03ecc
   return braced_lists_to_strings (type, ctor, false);
f03ecc
 }
f03ecc
 
f03ecc
+
f03ecc
+/* Emit debug for functions before finalizing early debug.  */
f03ecc
+
f03ecc
+void
f03ecc
+c_common_finalize_early_debug (void)
f03ecc
+{
f03ecc
+  /* Emit early debug for reachable functions, and by consequence,
f03ecc
+     locally scoped symbols.  Also emit debug for extern declared
f03ecc
+     functions that are still reachable at this point.  */
f03ecc
+  struct cgraph_node *cnode;
f03ecc
+  FOR_EACH_FUNCTION (cnode)
f03ecc
+    if (!cnode->alias && !cnode->thunk.thunk_p
f03ecc
+	&& (cnode->has_gimple_body_p () || !DECL_IS_BUILTIN (cnode->decl)))
f03ecc
+      (*debug_hooks->early_global_decl) (cnode->decl);
f03ecc
+}
f03ecc
+
f03ecc
 #include "gt-c-family-c-common.h"
f03ecc
--- gcc/c-family/c-common.h
f03ecc
+++ gcc/c-family/c-common.h
f03ecc
@@ -885,6 +885,8 @@ extern bool bool_promoted_to_int_p (tree);
f03ecc
 extern tree fold_for_warn (tree);
f03ecc
 extern tree c_common_get_narrower (tree, int *);
f03ecc
 extern bool get_attribute_operand (tree, unsigned HOST_WIDE_INT *);
f03ecc
+extern void c_common_finalize_early_debug (void);
f03ecc
+
f03ecc
 
f03ecc
 #define c_sizeof(LOC, T)  c_sizeof_or_alignof_type (LOC, T, true, false, 1)
f03ecc
 #define c_alignof(LOC, T) c_sizeof_or_alignof_type (LOC, T, false, false, 1)
f03ecc
--- gcc/c/c-objc-common.h
f03ecc
+++ gcc/c/c-objc-common.h
f03ecc
@@ -65,6 +65,8 @@ along with GCC; see the file COPYING3.  If not see
f03ecc
   c_simulate_builtin_function_decl
f03ecc
 #undef LANG_HOOKS_EMITS_BEGIN_STMT
f03ecc
 #define LANG_HOOKS_EMITS_BEGIN_STMT true
f03ecc
+#undef LANG_HOOKS_FINALIZE_EARLY_DEBUG
f03ecc
+#define LANG_HOOKS_FINALIZE_EARLY_DEBUG c_common_finalize_early_debug
f03ecc
 
f03ecc
 /* Attribute hooks.  */
f03ecc
 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
f03ecc
--- gcc/cgraphunit.c
f03ecc
+++ gcc/cgraphunit.c
f03ecc
@@ -2998,11 +2998,9 @@ symbol_table::finalize_compilation_unit (void)
f03ecc
 
f03ecc
   if (!seen_error ())
f03ecc
     {
f03ecc
-      /* Emit early debug for reachable functions, and by consequence,
f03ecc
-	 locally scoped symbols.  */
f03ecc
-      struct cgraph_node *cnode;
f03ecc
-      FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
f03ecc
-	(*debug_hooks->early_global_decl) (cnode->decl);
f03ecc
+      /* Give the frontends the chance to emit early debug based on
f03ecc
+	 what is still reachable in the TU.  */
f03ecc
+      (*lang_hooks.finalize_early_debug) ();
f03ecc
 
f03ecc
       /* Clean up anything that needs cleaning up after initial debug
f03ecc
 	 generation.  */
f03ecc
--- gcc/cp/cp-objcp-common.h
f03ecc
+++ gcc/cp/cp-objcp-common.h
f03ecc
@@ -115,6 +115,8 @@ extern tree cxx_simulate_enum_decl (location_t, const char *,
f03ecc
 #define LANG_HOOKS_BLOCK_MAY_FALLTHRU cxx_block_may_fallthru
f03ecc
 #undef LANG_HOOKS_EMITS_BEGIN_STMT
f03ecc
 #define LANG_HOOKS_EMITS_BEGIN_STMT true
f03ecc
+#undef LANG_HOOKS_FINALIZE_EARLY_DEBUG
f03ecc
+#define LANG_HOOKS_FINALIZE_EARLY_DEBUG c_common_finalize_early_debug
f03ecc
 
f03ecc
 /* Attribute hooks.  */
f03ecc
 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
f03ecc
--- gcc/langhooks-def.h
f03ecc
+++ gcc/langhooks-def.h
f03ecc
@@ -92,6 +92,7 @@ extern const char *lhd_get_substring_location (const substring_loc &,
f03ecc
 					       location_t *out_loc);
f03ecc
 extern int lhd_decl_dwarf_attribute (const_tree, int);
f03ecc
 extern int lhd_type_dwarf_attribute (const_tree, int);
f03ecc
+extern void lhd_finalize_early_debug (void);
f03ecc
 
f03ecc
 #define LANG_HOOKS_NAME			"GNU unknown"
f03ecc
 #define LANG_HOOKS_IDENTIFIER_SIZE	sizeof (struct lang_identifier)
f03ecc
@@ -139,6 +140,7 @@ extern int lhd_type_dwarf_attribute (const_tree, int);
f03ecc
 #define LANG_HOOKS_EMITS_BEGIN_STMT	false
f03ecc
 #define LANG_HOOKS_RUN_LANG_SELFTESTS   lhd_do_nothing
f03ecc
 #define LANG_HOOKS_GET_SUBSTRING_LOCATION lhd_get_substring_location
f03ecc
+#define LANG_HOOKS_FINALIZE_EARLY_DEBUG lhd_finalize_early_debug
f03ecc
 
f03ecc
 /* Attribute hooks.  */
f03ecc
 #define LANG_HOOKS_ATTRIBUTE_TABLE		NULL
f03ecc
@@ -364,7 +366,8 @@ extern void lhd_end_section (void);
f03ecc
   LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS, \
f03ecc
   LANG_HOOKS_EMITS_BEGIN_STMT, \
f03ecc
   LANG_HOOKS_RUN_LANG_SELFTESTS, \
f03ecc
-  LANG_HOOKS_GET_SUBSTRING_LOCATION \
f03ecc
+  LANG_HOOKS_GET_SUBSTRING_LOCATION, \
f03ecc
+  LANG_HOOKS_FINALIZE_EARLY_DEBUG \
f03ecc
 }
f03ecc
 
f03ecc
 #endif /* GCC_LANG_HOOKS_DEF_H */
f03ecc
--- gcc/langhooks.c
f03ecc
+++ gcc/langhooks.c
f03ecc
@@ -36,6 +36,8 @@ along with GCC; see the file COPYING3.  If not see
f03ecc
 #include "output.h"
f03ecc
 #include "timevar.h"
f03ecc
 #include "stor-layout.h"
f03ecc
+#include "cgraph.h"
f03ecc
+#include "debug.h"
f03ecc
 
f03ecc
 /* Do nothing; in many cases the default hook.  */
f03ecc
 
f03ecc
@@ -866,6 +868,18 @@ lhd_unit_size_without_reusable_padding (tree t)
f03ecc
   return TYPE_SIZE_UNIT (t);
f03ecc
 }
f03ecc
 
f03ecc
+/* Default implementation for the finalize_early_debug hook.  */
f03ecc
+
f03ecc
+void
f03ecc
+lhd_finalize_early_debug (void)
f03ecc
+{
f03ecc
+  /* Emit early debug for reachable functions, and by consequence,
f03ecc
+     locally scoped symbols.  */
f03ecc
+  struct cgraph_node *cnode;
f03ecc
+  FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
f03ecc
+    (*debug_hooks->early_global_decl) (cnode->decl);
f03ecc
+}
f03ecc
+
f03ecc
 /* Returns true if the current lang_hooks represents the GNU C frontend.  */
f03ecc
 
f03ecc
 bool
f03ecc
--- gcc/langhooks.h
f03ecc
+++ gcc/langhooks.h
f03ecc
@@ -580,6 +580,9 @@ struct lang_hooks
f03ecc
   const char *(*get_substring_location) (const substring_loc &,
f03ecc
 					 location_t *out_loc);
f03ecc
 
f03ecc
+  /* Invoked before the early_finish debug hook is invoked.  */
f03ecc
+  void (*finalize_early_debug) (void);
f03ecc
+
f03ecc
   /* Whenever you add entries here, make sure you adjust langhooks-def.h
f03ecc
      and langhooks.c accordingly.  */
f03ecc
 };
f03ecc
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr96383-1.c
f03ecc
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr96383-1.c
f03ecc
@@ -0,0 +1,17 @@
f03ecc
+/* { dg-do compile } */
f03ecc
+/* { dg-options "-g -gdwarf -dA" } */
f03ecc
+
f03ecc
+extern void foo (int);
f03ecc
+extern void unusedbar (int);
f03ecc
+
f03ecc
+int main()
f03ecc
+{
f03ecc
+  foo (1);
f03ecc
+}
f03ecc
+
f03ecc
+/* We want subprogram DIEs for both foo and main and a DIE for
f03ecc
+   the formal parameter of foo.  We do not want a DIE for
f03ecc
+   unusedbar.  */
f03ecc
+/* { dg-final { scan-assembler-times "DW_TAG_subprogram" 4 } } */
f03ecc
+/* { dg-final { scan-assembler-times "DW_TAG_formal_parameter" 2 } } */
f03ecc
+/* { dg-final { scan-assembler-not "unusedbar" } } */
f03ecc
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr96383-2.c
f03ecc
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr96383-2.c
f03ecc
@@ -0,0 +1,17 @@
f03ecc
+/* { dg-do compile } */
f03ecc
+/* { dg-options "-g -O2 -gdwarf -dA" } */
f03ecc
+
f03ecc
+extern void foo (int);
f03ecc
+extern void unusedbar (int);
f03ecc
+
f03ecc
+int main()
f03ecc
+{
f03ecc
+  foo (1);
f03ecc
+}
f03ecc
+
f03ecc
+/* We want subprogram DIEs for both foo and main and a DIE for
f03ecc
+   the formal parameter of foo.  We do not want a DIE for
f03ecc
+   unusedbar.  */
f03ecc
+/* { dg-final { scan-assembler-times "DW_TAG_subprogram" 4 } } */
f03ecc
+/* { dg-final { scan-assembler-times "DW_TAG_formal_parameter" 2 } } */
f03ecc
+/* { dg-final { scan-assembler-not "unusedbar" } } */
f03ecc
--- libstdc++-v3/testsuite/20_util/assume_aligned/3.cc
f03ecc
+++ libstdc++-v3/testsuite/20_util/assume_aligned/3.cc
f03ecc
@@ -15,7 +15,7 @@
f03ecc
 // with this library; see the file COPYING3.  If not see
f03ecc
 // <http://www.gnu.org/licenses/>.
f03ecc
 
f03ecc
-// { dg-options "-std=gnu++2a -O2" }
f03ecc
+// { dg-options "-std=gnu++2a -O2 -g0" }
f03ecc
 // { dg-do compile { target c++2a } }
f03ecc
 // { dg-final { scan-assembler-not "undefined" } }
f03ecc