aboutsummaryrefslogtreecommitdiff
path: root/gcc/dwarf2out.c
diff options
context:
space:
mode:
authorAlexandre Oliva <oliva@adacore.com>2019-10-01 11:36:31 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2019-10-01 11:36:31 +0000
commit31632e2c4327146ea8d21cff33adaa505b17d2bd (patch)
tree6a454c924b23547a07d090fa1686f7df8b8ad7fe /gcc/dwarf2out.c
parentc7ea76ea5629e9f0357de49847274cf80e35f2f8 (diff)
downloadgcc-31632e2c4327146ea8d21cff33adaa505b17d2bd.zip
gcc-31632e2c4327146ea8d21cff33adaa505b17d2bd.tar.gz
gcc-31632e2c4327146ea8d21cff33adaa505b17d2bd.tar.bz2
DWARF array bounds missing from C++ array definitions
A variable redeclaration or definition that provides additional type information for it, e.g. outermost array bounds, is not reflected in the debug information for the variable. With this patch, the debug info of the variable specialization gets a type attribute with the adjusted type. This patch affects mostly only array bounds. However, when the symbolic type used in a declaration and in a definition are different, although they refer to the same type, debug information will end up (correctly?) naming different symbolic types in the specification and the definition. Also, when a readonly declaration of an array loses the readonly flag at the definition because of the initializer, the definition may end up referencing a type while the specification refers to a const-qualified version of that type. If the type of the variable is already const-qualified, e.g. an array of a const type, the difference is meaningless. for gcc/ChangeLog PR debug/91507 * dwarf2out.c (override_type_for_decl_p): New. (gen_variable_die): Use it. for gcc/testsuite/ChangeLog PR debug/91507 * gcc.dg/debug/dwarf2/array-0.c: New. * gcc.dg/debug/dwarf2/array-1.c: New. * gcc.dg/debug/dwarf2/array-2.c: New. * gcc.dg/debug/dwarf2/array-3.c: New. * g++.dg/debug/dwarf2/array-0.C: New. * g++.dg/debug/dwarf2/array-1.C: New. * g++.dg/debug/dwarf2/array-2.C: New. Based on libstdc++-v3's src/c++98/pool_allocator.cc:__pool_alloc_base::_S_heap_size. * g++.dg/debug/dwarf2/array-3.C: New. Based on gcc's config/i386/i386-features.c:xlogue_layout::s_instances. * g++.dg/debug/dwarf2/array-4.C: New. From-SVN: r276403
Diffstat (limited to 'gcc/dwarf2out.c')
-rw-r--r--gcc/dwarf2out.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index d33f19b..bf69ce4 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -23705,6 +23705,34 @@ local_function_static (tree decl)
&& TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL;
}
+/* Return true iff DECL overrides (presumably completes) the type of
+ OLD_DIE within CONTEXT_DIE. */
+
+static bool
+override_type_for_decl_p (tree decl, dw_die_ref old_die,
+ dw_die_ref context_die)
+{
+ tree type = TREE_TYPE (decl);
+ int cv_quals;
+
+ if (decl_by_reference_p (decl))
+ {
+ type = TREE_TYPE (type);
+ cv_quals = TYPE_UNQUALIFIED;
+ }
+ else
+ cv_quals = decl_quals (decl);
+
+ dw_die_ref type_die = modified_type_die (type,
+ cv_quals | TYPE_QUALS (type),
+ false,
+ context_die);
+
+ dw_die_ref old_type_die = get_AT_ref (old_die, DW_AT_type);
+
+ return type_die != old_type_die;
+}
+
/* Generate a DIE to represent a declared data object.
Either DECL or ORIGIN must be non-null. */
@@ -23957,7 +23985,9 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
&& !DECL_ABSTRACT_P (decl_or_origin)
&& variably_modified_type_p (TREE_TYPE (decl_or_origin),
decl_function_context
- (decl_or_origin))))
+ (decl_or_origin)))
+ || (old_die && specialization_p
+ && override_type_for_decl_p (decl_or_origin, old_die, context_die)))
{
tree type = TREE_TYPE (decl_or_origin);