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