Blame SOURCES/gcc10-pr96383.patch

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