Blame SOURCES/gcc10-pr96383.patch

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