]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
authorMark Wielaard <mjw@redhat.com>
Wed, 21 May 2014 15:44:59 +0000 (15:44 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Wed, 21 May 2014 15:44:59 +0000 (15:44 +0000)
Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. The default implementation will just use type_for_size.
The implementation for C++ will use the ENUM_UNDERLYING_TYPE if it exists.
Use this enum_underlying_base_type lang-hook in dwarf2out.c to add a
DW_AT_type base type reference to a DW_TAG_enumeration.

gcc/
* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF
version >= 3 or not strict DWARF.
* langhooks.h (struct lang_hooks_for_types): Add
enum_underlying_base_type.
* langhooks.c (lhd_enum_underlying_base_type): New function.
* gcc/langhooks.h (struct lang_hooks_for_types): Add
enum_underlying_base_type.
* langhooks-def.h (lhd_enum_underlying_base_type): New declaration.
(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/cp/
* cp-lang.c (cxx_enum_underlying_base_type): New function.
(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

From-SVN: r210717

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/cp-lang.c
gcc/dwarf2out.c
gcc/langhooks-def.h
gcc/langhooks.c
gcc/langhooks.h

index d506727b18100943866e2c5d080adb867741f5ae..452b4b0e6df7f68a60ff9d0887ac2a7dca6d535d 100644 (file)
@@ -1,3 +1,17 @@
+2014-05-21  Mark Wielaard  <mjw@redhat.com>
+
+       PR debug/16063
+       * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF
+       version >= 3 or not strict DWARF.
+       * langhooks.h (struct lang_hooks_for_types): Add
+       enum_underlying_base_type.
+       * langhooks.c (lhd_enum_underlying_base_type): New function.
+       * gcc/langhooks.h (struct lang_hooks_for_types): Add
+       enum_underlying_base_type.
+       * langhooks-def.h (lhd_enum_underlying_base_type): New declaration.
+       (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+       (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-05-21  Richard Biener  <rguenther@suse.de>
 
        * doc/invoke.texi (-flto-partition=): Document one and
index adde47f5569dfa75c268f3a99e9c5c7b3946dee1..b0a06b1df8323ef18f9e4d2c3113b69701c5c170 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-21  Mark Wielaard  <mjw@redhat.com>
+
+       PR debug/16063
+       * cp-lang.c (cxx_enum_underlying_base_type): New function.
+       (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-05-21  Richard Sandiford  <rsandifo@linux.vnet.ibm.com>
 
        * cvt.c (convert_to_void): Use void_node instead of void_zero_node.
index c28c07a9d1f0be7f1e8ecc1dc562e72885a3da85..014f393ecfa71ffa62a84ee3807e49bb3007afd6 100644 (file)
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "stor-layout.h"
 #include "cp-tree.h"
 #include "c-family/c-common.h"
 #include "langhooks.h"
@@ -40,6 +41,7 @@ static enum classify_record cp_classify_record (tree type);
 static tree cp_eh_personality (void);
 static tree get_template_innermost_arguments_folded (const_tree);
 static tree get_template_argument_pack_elems_folded (const_tree);
+static tree cxx_enum_underlying_base_type (const_tree);
 
 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
    consequently, there should be very few hooks below.  */
@@ -81,6 +83,8 @@ static tree get_template_argument_pack_elems_folded (const_tree);
 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
 #undef LANG_HOOKS_EH_RUNTIME_TYPE
 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
 
 /* Each front end provides its own lang hook initializer.  */
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
@@ -219,5 +223,21 @@ get_template_argument_pack_elems_folded (const_tree t)
   return fold_cplus_constants (get_template_argument_pack_elems (t));
 }
 
+/* The C++ version of the enum_underlying_base_type langhook.
+   See also cp/semantics.c (finish_underlying_type).  */
+
+static
+tree cxx_enum_underlying_base_type (const_tree type)
+{
+  tree underlying_type = ENUM_UNDERLYING_TYPE (type);
+
+  if (! ENUM_FIXED_UNDERLYING_TYPE_P (type))
+    underlying_type
+      = c_common_type_for_mode (TYPE_MODE (underlying_type),
+                                TYPE_UNSIGNED (underlying_type));
+
+  return underlying_type;
+}
+
 #include "gt-cp-cp-lang.h"
 #include "gtype-cp.h"
index 4ea05a5b8420ac926c9000f392ce083cb3378f53..7c930746e7b384cc2700ada807dbb9397f3ed0b4 100644 (file)
@@ -17537,6 +17537,11 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (dwarf_version >= 3 || !dwarf_strict)
+       {
+         tree underlying = lang_hooks.types.enum_underlying_base_type (type);
+         add_type_attribute (type_die, underlying, 0, 0, context_die);
+       }
       if (TYPE_STUB_DECL (type) != NULL_TREE)
        {
          add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
index 95bd37933291ca30f6e6adbff4e3221210126f8a..d9a1dfdc194bc13af302926b0032041630265a1c 100644 (file)
@@ -60,6 +60,7 @@ extern size_t lhd_tree_size (enum tree_code);
 extern HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT);
 extern tree lhd_expr_to_decl (tree, bool *, bool *);
 extern tree lhd_builtin_function (tree);
+extern tree lhd_enum_underlying_base_type (const_tree);
 
 /* Declarations of default tree inlining hooks.  */
 extern void lhd_initialize_diagnostics (diagnostic_context *);
@@ -173,6 +174,7 @@ extern tree lhd_make_node (enum tree_code);
 #define LANG_HOOKS_GET_SUBRANGE_BOUNDS NULL
 #define LANG_HOOKS_DESCRIPTIVE_TYPE    NULL
 #define LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE reconstruct_complex_type
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE lhd_enum_underlying_base_type
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +193,8 @@ extern tree lhd_make_node (enum tree_code);
   LANG_HOOKS_GET_ARRAY_DESCR_INFO, \
   LANG_HOOKS_GET_SUBRANGE_BOUNDS, \
   LANG_HOOKS_DESCRIPTIVE_TYPE, \
-  LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE \
+  LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE, \
+  LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE \
 }
 
 /* Declaration hooks.  */
index d00ebd8a08c75ef350c31ca902f15f76949e425b..8f65c6860a54a92b51b29e2595b4bb5a5a41838f 100644 (file)
@@ -678,3 +678,12 @@ lhd_end_section (void)
       saved_section = NULL;
     }
 }
+
+/* Default implementation of enum_underlying_base_type using type_for_size.  */
+
+tree
+lhd_enum_underlying_base_type (const_tree enum_type)
+{
+  return lang_hooks.types.type_for_size (TYPE_PRECISION (enum_type),
+                                        TYPE_UNSIGNED (enum_type));
+}
index c848b0c5911f24ffd9f433fd62c720abdeae8ace..35b47bc6574b3de494d9dcc00328c0872fbce456 100644 (file)
@@ -137,6 +137,12 @@ struct lang_hooks_for_types
      return values from functions.  The argument TYPE is the top of the
      chain, and BOTTOM is the new type which we will point to.  */
   tree (*reconstruct_complex_type) (tree, tree);
+
+  /* Returns the tree that represents the underlying data type used to
+     implement the enumeration.  The default implementation will just use
+     type_for_size.  Used in dwarf2out.c to add a DW_AT_type base type
+     reference to a DW_TAG_enumeration.  */
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */