public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
@ 2014-03-23 11:32 Mark Wielaard
  2014-03-24  9:29 ` Richard Biener
  2014-03-24 17:04 ` Cary Coutant
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-03-23 11:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: Tom Tromey, Mark Wielaard

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 9255 bytes --]

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. Including implementations for C and C++. 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
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/c-family/
	* c-common.c (c_enum_underlying_base_type): New function.
	* c-common.h (c_enum_underlying_base_type): Add declaration.

gcc/c/
	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

gcc/cp/
	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
---
 gcc/ChangeLog           |   10 ++++++++++
 gcc/c-family/ChangeLog  |    6 ++++++
 gcc/c-family/c-common.c |    8 ++++++++
 gcc/c-family/c-common.h |    1 +
 gcc/c/ChangeLog         |    5 +++++
 gcc/c/c-objc-common.h   |    2 ++
 gcc/cp/ChangeLog        |    6 ++++++
 gcc/cp/cp-lang.c        |   18 ++++++++++++++++++
 gcc/dwarf2out.c         |    7 +++++++
 gcc/langhooks-def.h     |    4 +++-
 gcc/langhooks.h         |    2 ++
 11 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f3b4f2d..e90ea6e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-21  Mark Wielaard  <mjw@redhat.com>
 
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
 	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
 	as unsigned or int depending on type and value used.
 
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 4e5aea4..90b688b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-03-13  Jakub Jelinek  <jakub@redhat.com>
 
 	PR middle-end/36282
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index abd96fb..55ebbcc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 1099b10..e378b44 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b39b7d6..9ab6eab 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-03-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
 	PR c/55383
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3cf6858..8e6508e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-03-17  Adam Butcher  <adam@jessamine.co.uk>
 
 	PR c++/60390
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index af97408..554f787 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17339,6 +17339,13 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (dwarf_version >= 3 || !dwarf_strict))
+	{
+	  tree underlying = lang_hooks.types.enum_underlying_base_type (type);
+	  dw_die_ref underlying_die = base_type_die (underlying);
+	  add_AT_die_ref (type_die, DW_AT_type, underlying_die);
+	}
       if (TYPE_STUB_DECL (type) != NULL_TREE)
 	{
 	  add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */
-- 
1.7.1

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-23 11:32 [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration Mark Wielaard
@ 2014-03-24  9:29 ` Richard Biener
  2014-03-24 10:49   ` Mark Wielaard
  2014-03-24 17:04 ` Cary Coutant
  1 sibling, 1 reply; 29+ messages in thread
From: Richard Biener @ 2014-03-24  9:29 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: GCC Patches, Tom Tromey

On Sun, Mar 23, 2014 at 12:18 PM, Mark Wielaard <mjw@redhat.com> wrote:
> Add a new lang-hook that provides the underlying base type of an
> ENUMERAL_TYPE. Including implementations for C and C++. 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.

Don't we have TREE_TYPE (enum-type) as that type?  Thus, can we avoid
adding the new langhook?

Thanks,
Richard.

> gcc/
>         * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
>         enum_underlying_base_type defined and DWARF version > 3.
>         * langhooks.h (struct lang_hooks_for_types): Add
>         enum_underlying_base_type.
>         * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
>         (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
>
> gcc/c-family/
>         * c-common.c (c_enum_underlying_base_type): New function.
>         * c-common.h (c_enum_underlying_base_type): Add declaration.
>
> gcc/c/
>         * c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
>
> gcc/cp/
>         * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
>         enum_underlying_base_type defined and DWARF version > 3.
>         * langhooks.h (struct lang_hooks_for_types): Add
>         enum_underlying_base_type.
>         * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
>         (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
> ---
>  gcc/ChangeLog           |   10 ++++++++++
>  gcc/c-family/ChangeLog  |    6 ++++++
>  gcc/c-family/c-common.c |    8 ++++++++
>  gcc/c-family/c-common.h |    1 +
>  gcc/c/ChangeLog         |    5 +++++
>  gcc/c/c-objc-common.h   |    2 ++
>  gcc/cp/ChangeLog        |    6 ++++++
>  gcc/cp/cp-lang.c        |   18 ++++++++++++++++++
>  gcc/dwarf2out.c         |    7 +++++++
>  gcc/langhooks-def.h     |    4 +++-
>  gcc/langhooks.h         |    2 ++
>  11 files changed, 68 insertions(+), 1 deletions(-)
>
> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
> index f3b4f2d..e90ea6e 100644
> --- a/gcc/ChangeLog
> +++ b/gcc/ChangeLog
> @@ -1,5 +1,15 @@
>  2014-03-21  Mark Wielaard  <mjw@redhat.com>
>
> +       PR debug/16063
> +       * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
> +       enum_underlying_base_type defined and DWARF version > 3.
> +       * langhooks.h (struct lang_hooks_for_types): Add
> +       enum_underlying_base_type.
> +       * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
> +       (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
> +
> +2014-03-21  Mark Wielaard  <mjw@redhat.com>
> +
>         * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
>         as unsigned or int depending on type and value used.
>
> diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
> index 4e5aea4..90b688b 100644
> --- a/gcc/c-family/ChangeLog
> +++ b/gcc/c-family/ChangeLog
> @@ -1,3 +1,9 @@
> +2014-03-21  Mark Wielaard  <mjw@redhat.com>
> +
> +       PR debug/16063
> +       * c-common.c (c_enum_underlying_base_type): New function.
> +       * c-common.h (c_enum_underlying_base_type): Add declaration.
> +
>  2014-03-13  Jakub Jelinek  <jakub@redhat.com>
>
>         PR middle-end/36282
> diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
> index abd96fb..55ebbcc 100644
> --- a/gcc/c-family/c-common.c
> +++ b/gcc/c-family/c-common.c
> @@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
>
>    registered_builtin_types = tree_cons (0, type, registered_builtin_types);
>  }
> +
> +/* The C version of the enum_underlying_base_type langhook.  */
> +tree
> +c_enum_underlying_base_type (const_tree type)
> +{
> +  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
> +}
> +
>
>  /* Print an error message for invalid operands to arith operation
>     CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
> diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
> index 1099b10..e378b44 100644
> --- a/gcc/c-family/c-common.h
> +++ b/gcc/c-family/c-common.h
> @@ -832,6 +832,7 @@ extern void c_common_finish (void);
>  extern void c_common_parse_file (void);
>  extern alias_set_type c_common_get_alias_set (tree);
>  extern void c_register_builtin_type (tree, const char*);
> +extern tree c_enum_underlying_base_type (const_tree);
>  extern bool c_promoting_integer_type_p (const_tree);
>  extern int self_promoting_args_p (const_tree);
>  extern tree strip_pointer_operator (tree);
> diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
> index b39b7d6..9ab6eab 100644
> --- a/gcc/c/ChangeLog
> +++ b/gcc/c/ChangeLog
> @@ -1,3 +1,8 @@
> +2014-03-21  Mark Wielaard  <mjw@redhat.com>
> +
> +       PR debug/16063
> +       * c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
> +
>  2014-03-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
>
>         PR c/55383
> diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
> index 92cf60f..0651db7 100644
> --- a/gcc/c/c-objc-common.h
> +++ b/gcc/c/c-objc-common.h
> @@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
>  #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
>  #undef LANG_HOOKS_EXPR_TO_DECL
>  #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
> +#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
> +#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
>
>  /* The C front end's scoping structure is very different from
>     that expected by the language-independent code; it is best
> diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
> index 3cf6858..8e6508e 100644
> --- a/gcc/cp/ChangeLog
> +++ b/gcc/cp/ChangeLog
> @@ -1,3 +1,9 @@
> +2014-03-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-03-17  Adam Butcher  <adam@jessamine.co.uk>
>
>         PR c++/60390
> diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
> index c28c07a..6a40d29 100644
> --- a/gcc/cp/cp-lang.c
> +++ b/gcc/cp/cp-lang.c
> @@ -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,19 @@ 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"
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index af97408..554f787 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -17339,6 +17339,13 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
>
>        TREE_ASM_WRITTEN (type) = 1;
>        add_byte_size_attribute (type_die, type);
> +      if (lang_hooks.types.enum_underlying_base_type != NULL
> +         && (dwarf_version >= 3 || !dwarf_strict))
> +       {
> +         tree underlying = lang_hooks.types.enum_underlying_base_type (type);
> +         dw_die_ref underlying_die = base_type_die (underlying);
> +         add_AT_die_ref (type_die, DW_AT_type, underlying_die);
> +       }
>        if (TYPE_STUB_DECL (type) != NULL_TREE)
>         {
>           add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
> diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
> index 95bd379..b8e0d97 100644
> --- a/gcc/langhooks-def.h
> +++ b/gcc/langhooks-def.h
> @@ -173,6 +173,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 NULL
>
>  #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
>    LANG_HOOKS_MAKE_TYPE, \
> @@ -191,7 +192,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.  */
> diff --git a/gcc/langhooks.h b/gcc/langhooks.h
> index c848b0c..667298b 100644
> --- a/gcc/langhooks.h
> +++ b/gcc/langhooks.h
> @@ -137,6 +137,8 @@ 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);
> +
> +  tree (*enum_underlying_base_type) (const_tree);
>  };
>
>  /* Language hooks related to decls and the symbol table.  */
> --
> 1.7.1
>

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-24  9:29 ` Richard Biener
@ 2014-03-24 10:49   ` Mark Wielaard
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-03-24 10:49 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Tom Tromey

On Mon, 2014-03-24 at 10:26 +0100, Richard Biener wrote:
> On Sun, Mar 23, 2014 at 12:18 PM, Mark Wielaard <mjw@redhat.com> wrote:
> > Add a new lang-hook that provides the underlying base type of an
> > ENUMERAL_TYPE. Including implementations for C and C++. 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.
> 
> Don't we have TREE_TYPE (enum-type) as that type?  Thus, can we avoid
> adding the new langhook?

The underlying type is the integral base type of the enum, which, at
least for C++, can be different from the tree type of the enum. See also
cp/semantics.c (finish_underlying_type) which calculates it in the C++
case.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-23 11:32 [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration Mark Wielaard
  2014-03-24  9:29 ` Richard Biener
@ 2014-03-24 17:04 ` Cary Coutant
  2014-03-25 10:57   ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Cary Coutant @ 2014-03-24 17:04 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gcc-patches, Tom Tromey

> gcc/cp/
>         * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
>         enum_underlying_base_type defined and DWARF version > 3.
>         * langhooks.h (struct lang_hooks_for_types): Add
>         enum_underlying_base_type.
>         * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
>         (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

This should be the ChangeLog entry for cp/cp-lang.c.

-cary

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-24 17:04 ` Cary Coutant
@ 2014-03-25 10:57   ` Mark Wielaard
  2014-03-26 18:53     ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-03-25 10:57 UTC (permalink / raw)
  To: Cary Coutant; +Cc: gcc-patches, Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

On Mon, 2014-03-24 at 09:57 -0700, Cary Coutant wrote:
> > gcc/cp/
> >         * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
> >         enum_underlying_base_type defined and DWARF version > 3.
> >         * langhooks.h (struct lang_hooks_for_types): Add
> >         enum_underlying_base_type.
> >         * langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
> >         (LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
> 
> This should be the ChangeLog entry for cp/cp-lang.c.

Yes, you are right. Sorry for the copy/paste error.
Attached is the updated commit message and patch.

Thanks,

Mark

[-- Attachment #2: 0001-PR-debug-16063.-Add-DW_AT_type-to-DW_TAG_enumeration.patch --]
[-- Type: text/x-patch, Size: 9259 bytes --]

From b92c7933ebf8a09a97ca2419d253a0ac1acdca6f Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
Date: Sun, 23 Mar 2014 12:05:16 +0100
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. Including implementations for C and C++. 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
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/c-family/
	* c-common.c (c_enum_underlying_base_type): New function.
	* c-common.h (c_enum_underlying_base_type): Add declaration.

gcc/c/
	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

gcc/cp/
	* cp-lang.c (cxx_enum_underlying_base_type): New function.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
---
 gcc/ChangeLog           |   10 ++++++++++
 gcc/c-family/ChangeLog  |    6 ++++++
 gcc/c-family/c-common.c |    8 ++++++++
 gcc/c-family/c-common.h |    1 +
 gcc/c/ChangeLog         |    5 +++++
 gcc/c/c-objc-common.h   |    2 ++
 gcc/cp/ChangeLog        |    6 ++++++
 gcc/cp/cp-lang.c        |   18 ++++++++++++++++++
 gcc/dwarf2out.c         |    7 +++++++
 gcc/langhooks-def.h     |    4 +++-
 gcc/langhooks.h         |    2 ++
 11 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b456eff..7bce951 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-21  Mark Wielaard  <mjw@redhat.com>
 
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
 	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
 	as unsigned or int depending on type and value used.
 
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 536b4fc..94d779d 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-03-22  Jakub Jelinek  <jakub@redhat.com>
 
 	PR debug/60603
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index abd96fb..55ebbcc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 1099b10..e378b44 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b39b7d6..9ab6eab 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-03-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
 	PR c/55383
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1acfec3..8dad776 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-03-21  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	PR c++/60384
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index af97408..554f787 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17339,6 +17339,13 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (dwarf_version >= 3 || !dwarf_strict))
+	{
+	  tree underlying = lang_hooks.types.enum_underlying_base_type (type);
+	  dw_die_ref underlying_die = base_type_die (underlying);
+	  add_AT_die_ref (type_die, DW_AT_type, underlying_die);
+	}
       if (TYPE_STUB_DECL (type) != NULL_TREE)
 	{
 	  add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */
-- 
1.7.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-25 10:57   ` Mark Wielaard
@ 2014-03-26 18:53     ` Mark Wielaard
  2014-04-10 15:56       ` Tom Tromey
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-03-26 18:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

On irc Tom Tromey pointed out that the patch generates duplicate base
type DIEs for enums with the same underlying base type. This is because
it was calling base_type_die () and adding the DW_AT_type by hand
instead of calling add_type_attribute () to add it to the enumeration
DIE. The only difference with the original patch is the following:

  {
    tree underlying = lang_hooks.types.enum_underlying_base_type (type);
-   dw_die_ref underlying_die = base_type_die (underlying);
-   add_AT_die_ref (type_die, DW_AT_type, underlying_die);
+   add_type_attribute (type_die, underlying, 0, 0, context_die);
  }

This generates the same DWARF except for generating multiple instances
of the same base type DIE in case multiple enums in a CU share the same
underlying base type.

[-- Attachment #2: 0001-PR-debug-16063.-Add-DW_AT_type-to-DW_TAG_enumeration.patch --]
[-- Type: text/x-patch, Size: 9205 bytes --]

From 964dcd8a1aefb6bc733372aa42868ed3ad8a46d7 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
Date: Sun, 23 Mar 2014 12:05:16 +0100
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. Including implementations for C and C++. 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
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/c-family/
	* c-common.c (c_enum_underlying_base_type): New function.
	* c-common.h (c_enum_underlying_base_type): Add declaration.

gcc/c/
	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

gcc/cp/
	* cp-lang.c (cxx_enum_underlying_base_type): New function.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
---
 gcc/ChangeLog           |   10 ++++++++++
 gcc/c-family/ChangeLog  |    6 ++++++
 gcc/c-family/c-common.c |    8 ++++++++
 gcc/c-family/c-common.h |    1 +
 gcc/c/ChangeLog         |    5 +++++
 gcc/c/c-objc-common.h   |    2 ++
 gcc/cp/ChangeLog        |    6 ++++++
 gcc/cp/cp-lang.c        |   18 ++++++++++++++++++
 gcc/dwarf2out.c         |    6 ++++++
 gcc/langhooks-def.h     |    4 +++-
 gcc/langhooks.h         |    2 ++
 11 files changed, 67 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b456eff..7bce951 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-21  Mark Wielaard  <mjw@redhat.com>
 
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
 	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
 	as unsigned or int depending on type and value used.
 
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 536b4fc..94d779d 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-03-22  Jakub Jelinek  <jakub@redhat.com>
 
 	PR debug/60603
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index abd96fb..55ebbcc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 1099b10..e378b44 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b39b7d6..9ab6eab 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-03-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
 	PR c/55383
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1acfec3..8dad776 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-03-21  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	PR c++/60384
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index af97408..8c045cb 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17339,6 +17339,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */
-- 
1.7.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-03-26 18:53     ` Mark Wielaard
@ 2014-04-10 15:56       ` Tom Tromey
  2014-04-10 17:52         ` Cary Coutant
  0 siblings, 1 reply; 29+ messages in thread
From: Tom Tromey @ 2014-04-10 15:56 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gcc-patches

>>>>> "Mark" == Mark Wielaard <mjw@redhat.com> writes:

Mark> Add a new lang-hook that provides the underlying base type of an
Mark> ENUMERAL_TYPE. Including implementations for C and C++. Use this
Mark> enum_underlying_base_type lang-hook in dwarf2out.c to add a DW_AT_type
Mark> base type reference to a DW_TAG_enumeration.

Just FYI - I sent a patch for gdb to use this information.
I'll probably put it in before the gcc change goes in, on the theory
that when the gcc change goes in, nobody will have to wait to debug.
However it would be nice to be assured that the gcc change is ok in
principle first.

Tom

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-10 15:56       ` Tom Tromey
@ 2014-04-10 17:52         ` Cary Coutant
  2014-04-11  7:55           ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Cary Coutant @ 2014-04-10 17:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Mark Wielaard, gcc-patches

> However it would be nice to be assured that the gcc change is ok in
> principle first.

The DWARF bits are fine with me.

-cary

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-10 17:52         ` Cary Coutant
@ 2014-04-11  7:55           ` Mark Wielaard
  2014-04-11 18:03             ` Cary Coutant
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-04-11  7:55 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Tom Tromey, gcc-patches

On Thu, 2014-04-10 at 10:51 -0700, Cary Coutant wrote:
> > However it would be nice to be assured that the gcc change is ok in
> > principle first.
> 
> The DWARF bits are fine with me.

Thanks. Who can approve the other bits?
When approved should I wait till stage 1 opens before committing?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-11  7:55           ` Mark Wielaard
@ 2014-04-11 18:03             ` Cary Coutant
  2014-04-14 21:19               ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Cary Coutant @ 2014-04-11 18:03 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Tom Tromey, gcc-patches

>> The DWARF bits are fine with me.
>
> Thanks. Who can approve the other bits?

You should probably get C and C++ front end approval. I'm not really
sure who needs to review patches in c-family/. Since the part in c/ is
so tiny, maybe all you need is a C++ front end maintainer. Both
Richard Henderson and Jason Merrill are global reviewers, so either of
them could approve the whole thing.

> When approved should I wait till stage 1 opens before committing?

Yes. The PR you're fixing is an enhancement request, not a regression,
so it needs to wait.

-cary

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-11 18:03             ` Cary Coutant
@ 2014-04-14 21:19               ` Mark Wielaard
  2014-04-22 10:33                 ` Ping: " Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-04-14 21:19 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

On Fri, 2014-04-11 at 11:03 -0700, Cary Coutant wrote:
> >> The DWARF bits are fine with me.
> >
> > Thanks. Who can approve the other bits?
> 
> You should probably get C and C++ front end approval. I'm not really
> sure who needs to review patches in c-family/. Since the part in c/ is
> so tiny, maybe all you need is a C++ front end maintainer. Both
> Richard Henderson and Jason Merrill are global reviewers, so either of
> them could approve the whole thing.

Thanks, I added them to the CC.

> > When approved should I wait till stage 1 opens before committing?
> 
> Yes. The PR you're fixing is an enhancement request, not a regression,
> so it needs to wait.

Since stage one just opened up again this seems a good time to re-ask
for approval then :) Rebased patch against current trunk attached.

Thanks,

Mark



[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 8833 bytes --]

commit a5044d478738e2fbd471b8b9d98e1b37e5d8b64b
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sun Mar 23 12:05:16 2014 +0100

    PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
    
    Add a new lang-hook that provides the underlying base type of an
    ENUMERAL_TYPE. Including implementations for C and C++. 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
    	enum_underlying_base_type defined and DWARF version > 3.
    	* langhooks.h (struct lang_hooks_for_types): Add
    	enum_underlying_base_type.
    	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
    	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
    
    gcc/c-family/
    	* c-common.c (c_enum_underlying_base_type): New function.
    	* c-common.h (c_enum_underlying_base_type): Add declaration.
    
    gcc/c/
    	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
    
    gcc/cp/
    	* cp-lang.c (cxx_enum_underlying_base_type): New function.
    	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 355ba29..2a8f3ee 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
 2014-03-21  Mark Wielaard  <mjw@redhat.com>
 
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
 	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
 	as unsigned or int depending on type and value used.
 
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 206b47b..0b7b7e1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-04-14  Richard Biener  <rguenther@suse.de>
 	Marc Glisse  <marc.glisse@inria.fr>
 
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index c0e247b..a7c212f 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 24959d8..d433972 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index bacfbe3..cf4252b 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-04-12  Igor Zamyatin  <igor.zamyatin@intel.com>
 
 	PR middle-end/60469
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9510587..46308cb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-04-14  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	* cp-tree.h (TYPE_IDENTIFIER): Remove declaration.
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index d4e4b17..e71fce6 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17344,6 +17344,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Ping: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-14 21:19               ` Mark Wielaard
@ 2014-04-22 10:33                 ` Mark Wielaard
  2014-04-28 11:18                   ` Ping2: " Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-04-22 10:33 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

On Mon, 2014-04-14 at 23:19 +0200, Mark Wielaard wrote:
> On Fri, 2014-04-11 at 11:03 -0700, Cary Coutant wrote:
> > >> The DWARF bits are fine with me.
> > >
> > > Thanks. Who can approve the other bits?
> > 
> > You should probably get C and C++ front end approval. I'm not really
> > sure who needs to review patches in c-family/. Since the part in c/ is
> > so tiny, maybe all you need is a C++ front end maintainer. Both
> > Richard Henderson and Jason Merrill are global reviewers, so either of
> > them could approve the whole thing.
> 
> Thanks, I added them to the CC.
> 
> > > When approved should I wait till stage 1 opens before committing?
> > 
> > Yes. The PR you're fixing is an enhancement request, not a regression,
> > so it needs to wait.
> 
> Since stage one just opened up again this seems a good time to re-ask
> for approval then :) Rebased patch against current trunk attached.

Ping. Tom already pushed his patches to GDB that take advantage of the
new information if available.

Thanks,

Mark

[-- Attachment #2: 0001-PR-debug-16063.-Add-DW_AT_type-to-DW_TAG_enumeration.patch --]
[-- Type: text/x-patch, Size: 9157 bytes --]

From 81c76099294a9d617798ed65095d7f8210d6f958 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
Date: Sun, 23 Mar 2014 12:05:16 +0100
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. Including implementations for C and C++. 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
	enum_underlying_base_type defined and DWARF version > 3.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/c-family/
	* c-common.c (c_enum_underlying_base_type): New function.
	* c-common.h (c_enum_underlying_base_type): Add declaration.

gcc/c/
	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

gcc/cp/
	* cp-lang.c (cxx_enum_underlying_base_type): New function.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
---
 gcc/ChangeLog           |   10 ++++++++++
 gcc/c-family/ChangeLog  |    6 ++++++
 gcc/c-family/c-common.c |    8 ++++++++
 gcc/c-family/c-common.h |    1 +
 gcc/c/ChangeLog         |    5 +++++
 gcc/c/c-objc-common.h   |    2 ++
 gcc/cp/ChangeLog        |    6 ++++++
 gcc/cp/cp-lang.c        |   18 ++++++++++++++++++
 gcc/dwarf2out.c         |    6 ++++++
 gcc/langhooks-def.h     |    4 +++-
 gcc/langhooks.h         |    2 ++
 11 files changed, 67 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e34c39f..26a9037 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-04-22  Ian Bolton  <ian.bolton@arm.com>
 
 	* config/arm/arm-protos.h (tune_params): New struct members.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 206b47b..0b7b7e1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-04-14  Richard Biener  <rguenther@suse.de>
 	Marc Glisse  <marc.glisse@inria.fr>
 
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index c0e247b..a7c212f 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3902,6 +3902,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 24959d8..d433972 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index bacfbe3..cf4252b 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-04-12  Igor Zamyatin  <igor.zamyatin@intel.com>
 
 	PR middle-end/60469
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b7db350..7f187f7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-04-18  Jason Merrill  <jason@redhat.com>
 
 	DR 1571
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 8caf940..6bff040 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17346,6 +17346,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */
-- 
1.7.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-22 10:33                 ` Ping: " Mark Wielaard
@ 2014-04-28 11:18                   ` Mark Wielaard
  2014-04-28 12:37                     ` Jakub Jelinek
  2014-05-12  9:39                     ` Ping3: " Mark Wielaard
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-04-28 11:18 UTC (permalink / raw)
  To: Cary Coutant; +Cc: Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]

On Tue, 2014-04-22 at 12:31 +0200, Mark Wielaard wrote:
> On Mon, 2014-04-14 at 23:19 +0200, Mark Wielaard wrote:
> > On Fri, 2014-04-11 at 11:03 -0700, Cary Coutant wrote:
> > > >> The DWARF bits are fine with me.
> > > >
> > > > Thanks. Who can approve the other bits?
> > > 
> > > You should probably get C and C++ front end approval. I'm not really
> > > sure who needs to review patches in c-family/. Since the part in c/ is
> > > so tiny, maybe all you need is a C++ front end maintainer. Both
> > > Richard Henderson and Jason Merrill are global reviewers, so either of
> > > them could approve the whole thing.
> > 
> > Thanks, I added them to the CC.
> > 
> > > > When approved should I wait till stage 1 opens before committing?
> > > 
> > > Yes. The PR you're fixing is an enhancement request, not a regression,
> > > so it needs to wait.
> > 
> > Since stage one just opened up again this seems a good time to re-ask
> > for approval then :) Rebased patch against current trunk attached.
> 
> Ping. Tom already pushed his patches to GDB that take advantage of the
> new information if available.

Ping2. Please let me know if I should ping/cc other people to get this
reviewed.

Thanks,

Mark

[-- Attachment #2: enum_underlying_type.patch --]
[-- Type: text/x-patch, Size: 8726 bytes --]

commit 603223a974054aa52512ca08f36f1550692240e5
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sun Mar 23 12:05:16 2014 +0100

    PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
    
    Add a new lang-hook that provides the underlying base type of an
    ENUMERAL_TYPE. Including implementations for C and C++. 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
    	enum_underlying_base_type defined and DWARF version > 3.
    	* langhooks.h (struct lang_hooks_for_types): Add
    	enum_underlying_base_type.
    	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
    	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
    
    gcc/c-family/
    	* c-common.c (c_enum_underlying_base_type): New function.
    	* c-common.h (c_enum_underlying_base_type): Add declaration.
    
    gcc/c/
    	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
    
    gcc/cp/
    	* cp-lang.c (cxx_enum_underlying_base_type): New function.
    	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b25f1f6..766e0e7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-04-27  Richard Sandiford  <rdsandiford@googlemail.com>
 
 	* cselib.c (find_slot_memmode): Delete.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index fb0d102..e652c1b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-04-25  Marek Polacek  <polacek@redhat.com>
 
 	PR c/18079
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 0ad955d..6862c6f 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3906,6 +3906,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 57b7dce..25c3272 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 80841af..1eb3782 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-04-25  Marek Polacek  <polacek@redhat.com>
 
 	PR c/18079
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5840461..cd0055a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-04-24  Jakub Jelinek  <jakub@redhat.com>
 
 	* parser.c (cp_parser_omp_atomic): Allow seq_cst before
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 1272326..4beed2d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17368,6 +17368,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-28 11:18                   ` Ping2: " Mark Wielaard
@ 2014-04-28 12:37                     ` Jakub Jelinek
  2014-04-28 12:44                       ` Mark Wielaard
  2014-05-12  9:39                     ` Ping3: " Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Jakub Jelinek @ 2014-04-28 12:37 UTC (permalink / raw)
  To: Mark Wielaard
  Cc: Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

On Mon, Apr 28, 2014 at 01:17:32PM +0200, Mark Wielaard wrote:
> On Tue, 2014-04-22 at 12:31 +0200, Mark Wielaard wrote:
> > On Mon, 2014-04-14 at 23:19 +0200, Mark Wielaard wrote:
> > > On Fri, 2014-04-11 at 11:03 -0700, Cary Coutant wrote:
> > > > >> The DWARF bits are fine with me.
> > > > >
> > > > > Thanks. Who can approve the other bits?
> > > > 
> > > > You should probably get C and C++ front end approval. I'm not really
> > > > sure who needs to review patches in c-family/. Since the part in c/ is
> > > > so tiny, maybe all you need is a C++ front end maintainer. Both
> > > > Richard Henderson and Jason Merrill are global reviewers, so either of
> > > > them could approve the whole thing.
> > > 
> > > Thanks, I added them to the CC.
> > > 
> > > > > When approved should I wait till stage 1 opens before committing?
> > > > 
> > > > Yes. The PR you're fixing is an enhancement request, not a regression,
> > > > so it needs to wait.
> > > 
> > > Since stage one just opened up again this seems a good time to re-ask
> > > for approval then :) Rebased patch against current trunk attached.
> > 
> > Ping. Tom already pushed his patches to GDB that take advantage of the
> > new information if available.
> 
> Ping2. Please let me know if I should ping/cc other people to get this
> reviewed.

Do you want to add DW_AT_type to DW_TAG_enumeration only if it has explicit
underlying type (enum class foo: char { ... };) or even when the underlying
type is computed emplicitly (then you'd just use TREE_TYPE of the
ENUMERAL_TYPE if non-NULL).

	Jakub

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-28 12:37                     ` Jakub Jelinek
@ 2014-04-28 12:44                       ` Mark Wielaard
  2014-05-06  7:46                         ` Mark Wielaard
  2014-05-13  3:22                         ` Jason Merrill
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-04-28 12:44 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

On Mon, 2014-04-28 at 14:23 +0200, Jakub Jelinek wrote:
> On Mon, Apr 28, 2014 at 01:17:32PM +0200, Mark Wielaard wrote:
> > Ping2. Please let me know if I should ping/cc other people to get this
> > reviewed.
> 
> Do you want to add DW_AT_type to DW_TAG_enumeration only if it has explicit
> underlying type (enum class foo: char { ... };) or even when the underlying
> type is computed emplicitly (then you'd just use TREE_TYPE of the
> ENUMERAL_TYPE if non-NULL).

The debugger cares about the actual underlying type used if the language
can use multiple. Either explicitly assigned by the user or implicitly
as derived by the language/compile flags used. So the lang hook should
provide one in both cases, if appropriate.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-28 12:44                       ` Mark Wielaard
@ 2014-05-06  7:46                         ` Mark Wielaard
  2014-05-13  3:22                         ` Jason Merrill
  1 sibling, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-05-06  7:46 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]

On Mon, 2014-04-28 at 14:37 +0200, Mark Wielaard wrote:
> On Mon, 2014-04-28 at 14:23 +0200, Jakub Jelinek wrote:
> > On Mon, Apr 28, 2014 at 01:17:32PM +0200, Mark Wielaard wrote:
> > > Ping2. Please let me know if I should ping/cc other people to get this
> > > reviewed.
> > 
> > Do you want to add DW_AT_type to DW_TAG_enumeration only if it has explicit
> > underlying type (enum class foo: char { ... };) or even when the underlying
> > type is computed emplicitly (then you'd just use TREE_TYPE of the
> > ENUMERAL_TYPE if non-NULL).
> 
> The debugger cares about the actual underlying type used if the language
> can use multiple. Either explicitly assigned by the user or implicitly
> as derived by the language/compile flags used. So the lang hook should
> provide one in both cases, if appropriate.

Please let me know if that answered the question and whether that
information is enough to review the patch. I have attached a rebased
version against current trunk.

Thanks,

Mark

[-- Attachment #2: enum_underlying_type.patch --]
[-- Type: text/x-patch, Size: 8689 bytes --]

commit 6210291f2a8f01e989565ef0e7ba580144e67472
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sun Mar 23 12:05:16 2014 +0100

    PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
    
    Add a new lang-hook that provides the underlying base type of an
    ENUMERAL_TYPE. Including implementations for C and C++. 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
    	enum_underlying_base_type defined and DWARF version > 3.
    	* langhooks.h (struct lang_hooks_for_types): Add
    	enum_underlying_base_type.
    	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
    	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
    
    gcc/c-family/
    	* c-common.c (c_enum_underlying_base_type): New function.
    	* c-common.h (c_enum_underlying_base_type): Add declaration.
    
    gcc/c/
    	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
    
    gcc/cp/
    	* cp-lang.c (cxx_enum_underlying_base_type): New function.
    	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 41dee8f..d29281a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-05-05  Jan Hubicka  <hubicka@ucw.cz>
 
 	PR ipa/60965
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 3c97323..05e5b55 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-05-02  Marek Polacek  <polacek@redhat.com>
 
 	* c.opt (Wsizeof-pointer-memaccess): Describe option.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 0ad955d..6862c6f 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3906,6 +3906,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 57b7dce..25c3272 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -832,6 +832,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index e408fef..aa93750 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-05-02  Marek Polacek  <polacek@redhat.com>
 
 	PR c/25801
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 374cd0f..93206fc 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	PR c++/58582
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 1272326..4beed2d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17368,6 +17368,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Ping3: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-28 11:18                   ` Ping2: " Mark Wielaard
  2014-04-28 12:37                     ` Jakub Jelinek
@ 2014-05-12  9:39                     ` Mark Wielaard
  1 sibling, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-05-12  9:39 UTC (permalink / raw)
  To: Cary Coutant
  Cc: Jakub Jelinek, Tom Tromey, gcc-patches, Richard Henderson, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 1573 bytes --]

On Mon, 2014-04-28 at 13:17 +0200, Mark Wielaard wrote:
> On Tue, 2014-04-22 at 12:31 +0200, Mark Wielaard wrote:
> > On Mon, 2014-04-14 at 23:19 +0200, Mark Wielaard wrote:
> > > On Fri, 2014-04-11 at 11:03 -0700, Cary Coutant wrote:
> > > > >> The DWARF bits are fine with me.
> > > > >
> > > > > Thanks. Who can approve the other bits?
> > > > 
> > > > You should probably get C and C++ front end approval. I'm not really
> > > > sure who needs to review patches in c-family/. Since the part in c/ is
> > > > so tiny, maybe all you need is a C++ front end maintainer. Both
> > > > Richard Henderson and Jason Merrill are global reviewers, so either of
> > > > them could approve the whole thing.
> > > 
> > > Thanks, I added them to the CC.
> > > 
> > > > > When approved should I wait till stage 1 opens before committing?
> > > > 
> > > > Yes. The PR you're fixing is an enhancement request, not a regression,
> > > > so it needs to wait.
> > > 
> > > Since stage one just opened up again this seems a good time to re-ask
> > > for approval then :) Rebased patch against current trunk attached.
> > 
> > Ping. Tom already pushed his patches to GDB that take advantage of the
> > new information if available.
> 
> Ping2. Please let me know if I should ping/cc other people to get this
> reviewed.

Ping3. Rebased patch to current master attached. DWARF parts approved by
Cary, GDB already contains Tom's code to take advantage of the new
information. Please let me know if I need to take any other steps to get
this in an acceptable state and approved.

Thanks,

Mark

[-- Attachment #2: enum_underlying_type.patch --]
[-- Type: text/x-patch, Size: 8735 bytes --]

commit 58f1af6ee92a42d796cfd62f6158e2eb9f5969cb
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sun Mar 23 12:05:16 2014 +0100

    PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
    
    Add a new lang-hook that provides the underlying base type of an
    ENUMERAL_TYPE. Including implementations for C and C++. 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
    	enum_underlying_base_type defined and DWARF version > 3.
    	* langhooks.h (struct lang_hooks_for_types): Add
    	enum_underlying_base_type.
    	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
    	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
    
    gcc/c-family/
    	* c-common.c (c_enum_underlying_base_type): New function.
    	* c-common.h (c_enum_underlying_base_type): Add declaration.
    
    gcc/c/
    	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
    
    gcc/cp/
    	* cp-lang.c (cxx_enum_underlying_base_type): New function.
    	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f3cb5f7..567d268 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-05-11  Jakub Jelinek  <jakub@redhat.com>
 
 	* tree.h (OMP_CLAUSE_LINEAR_STMT): Define.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 3a978fa..c5ed7a2 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-05-09  Marek Polacek  <polacek@redhat.com>
 
 	PR c/50459
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a120b5c..fdc02b4 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3921,6 +3921,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index d34d2bb..d3d3004 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -833,6 +833,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 919b4ff..d2fb777 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-05-10  Marek Polacek  <polacek@redhat.com>
 
 	* c-parser.c (c_parser_declaration_or_fndef): Pass init_loc to
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5ddf555..94165f8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-09  Momchil Velikov  <momchil.velikov@gmail.com>
 
 	PR c++/60463
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5874d73..d906be2 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17540,6 +17540,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-04-28 12:44                       ` Mark Wielaard
  2014-05-06  7:46                         ` Mark Wielaard
@ 2014-05-13  3:22                         ` Jason Merrill
  2014-05-13  7:21                           ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Jason Merrill @ 2014-05-13  3:22 UTC (permalink / raw)
  To: Mark Wielaard, Jakub Jelinek
  Cc: Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On 04/28/2014 08:37 AM, Mark Wielaard wrote:
> On Mon, 2014-04-28 at 14:23 +0200, Jakub Jelinek wrote:
>> Do you want to add DW_AT_type to DW_TAG_enumeration only if it has explicit
>> underlying type (enum class foo: char { ... };) or even when the underlying
>> type is computed emplicitly (then you'd just use TREE_TYPE of the
>> ENUMERAL_TYPE if non-NULL).
>
> The debugger cares about the actual underlying type used if the language
> can use multiple. Either explicitly assigned by the user or implicitly
> as derived by the language/compile flags used. So the lang hook should
> provide one in both cases, if appropriate.

Why do you want to do this for C?  It seems to me that this is only 
interesting in C++ because of overload resolution.

Jason

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-13  3:22                         ` Jason Merrill
@ 2014-05-13  7:21                           ` Mark Wielaard
  2014-05-19 19:29                             ` Ping4: " Mark Wielaard
  2014-05-19 20:50                             ` Ping2: " Jason Merrill
  0 siblings, 2 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-05-13  7:21 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On Mon, May 12, 2014 at 11:22:11PM -0400, Jason Merrill wrote:
> On 04/28/2014 08:37 AM, Mark Wielaard wrote:
> >The debugger cares about the actual underlying type used if the language
> >can use multiple. Either explicitly assigned by the user or implicitly
> >as derived by the language/compile flags used. So the lang hook should
> >provide one in both cases, if appropriate.
> 
> Why do you want to do this for C?  It seems to me that this is only
> interesting in C++ because of overload resolution.

So the debugger doesn't have to guess the properties of the enum's
underlying base type, like size, encoding and signedness. Which are
implementation defined and might differ between enums even in C depending
on whether -fshort-enums was used (which is the default on some arches).

Cheers,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Ping4: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-13  7:21                           ` Mark Wielaard
@ 2014-05-19 19:29                             ` Mark Wielaard
  2014-05-19 20:50                             ` Ping2: " Jason Merrill
  1 sibling, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-05-19 19:29 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

Rebased patch to current master attached. DWARF parts approved by
Cary Coutant, GDB already contains Tom Tromey's code to take advantage
of the new information. Earlier discussions:
https://gcc.gnu.org/ml/gcc-patches/2014-04/msg00713.html
https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01859.html
https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00922.html
If there are any unanswered questions that might help getting this
reviewed, please let me know.

[-- Attachment #2: enum_underlying_type.patch --]
[-- Type: text/x-patch, Size: 8791 bytes --]

commit aa9d60cddb82d009055262b98aff97f395d73ba9
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sun Mar 23 12:05:16 2014 +0100

    PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
    
    Add a new lang-hook that provides the underlying base type of an
    ENUMERAL_TYPE. Including implementations for C and C++. 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
    	enum_underlying_base_type defined and DWARF version > 3.
    	* langhooks.h (struct lang_hooks_for_types): Add
    	enum_underlying_base_type.
    	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
    	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
    
    gcc/c-family/
    	* c-common.c (c_enum_underlying_base_type): New function.
    	* c-common.h (c_enum_underlying_base_type): Add declaration.
    
    gcc/c/
    	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
    
    gcc/cp/
    	* cp-lang.c (cxx_enum_underlying_base_type): New function.
    	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c69a30c..c368854 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if
+	enum_underlying_base_type defined and DWARF version > 3.
+	* langhooks.h (struct lang_hooks_for_types): Add
+	enum_underlying_base_type.
+	* langhooks-def.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
+	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.
+
 2014-05-19  Richard Biener  <rguenther@suse.de>
 
 	PR tree-optimization/61184
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index c88cf59..6ff8466 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-common.c (c_enum_underlying_base_type): New function.
+	* c-common.h (c_enum_underlying_base_type): Add declaration.
+
 2014-05-17  Trevor Saunders  <tsaunders@mozilla.com>
 
 	* c-common.h (sorted_fields_type): Remove variable_size GTY attribute.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a120b5c..fdc02b4 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3921,6 +3921,14 @@ c_register_builtin_type (tree type, const char* name)
 
   registered_builtin_types = tree_cons (0, type, registered_builtin_types);
 }
+
+/* The C version of the enum_underlying_base_type langhook.  */
+tree
+c_enum_underlying_base_type (const_tree type)
+{
+  return c_common_type_for_size (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+}
+
 \f
 /* Print an error message for invalid operands to arith operation
    CODE with TYPE0 for operand 0, and TYPE1 for operand 1.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 59e809a..478d8cb 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -833,6 +833,7 @@ extern void c_common_finish (void);
 extern void c_common_parse_file (void);
 extern alias_set_type c_common_get_alias_set (tree);
 extern void c_register_builtin_type (tree, const char*);
+extern tree c_enum_underlying_base_type (const_tree);
 extern bool c_promoting_integer_type_p (const_tree);
 extern int self_promoting_args_p (const_tree);
 extern tree strip_pointer_operator (tree);
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 1266d4e..431490d 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21  Mark Wielaard  <mjw@redhat.com>
+
+	PR debug/16063
+	* c-objc-common.h (LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.
+
 2014-05-17  Trevor Saunders  <tsaunders@mozilla.com>
 
 	* c-decl.c (finish_struct): Adjust.
diff --git a/gcc/c/c-objc-common.h b/gcc/c/c-objc-common.h
index 92cf60f..0651db7 100644
--- a/gcc/c/c-objc-common.h
+++ b/gcc/c/c-objc-common.h
@@ -84,6 +84,8 @@ along with GCC; see the file COPYING3.  If not see
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_EXPR_TO_DECL
 #define LANG_HOOKS_EXPR_TO_DECL c_expr_to_decl
+#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
+#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE c_enum_underlying_base_type
 
 /* The C front end's scoping structure is very different from
    that expected by the language-independent code; it is best
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b5ad1af..fb82778 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-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-17  Trevor Saunders  <tsaunders@mozilla.com>
 
 	* class.c (sorted_fields_type_new): Adjust.
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 4ea05a5..2d5546a 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17537,6 +17537,12 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
 
       TREE_ASM_WRITTEN (type) = 1;
       add_byte_size_attribute (type_die, type);
+      if (lang_hooks.types.enum_underlying_base_type != NULL
+	  && (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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..b8e0d97 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -173,6 +173,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 NULL
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -191,7 +192,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.  */
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-13  7:21                           ` Mark Wielaard
  2014-05-19 19:29                             ` Ping4: " Mark Wielaard
@ 2014-05-19 20:50                             ` Jason Merrill
  2014-05-20  6:55                               ` Mark Wielaard
  1 sibling, 1 reply; 29+ messages in thread
From: Jason Merrill @ 2014-05-19 20:50 UTC (permalink / raw)
  To: Mark Wielaard
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On 05/13/2014 03:21 AM, Mark Wielaard wrote:
> So the debugger doesn't have to guess the properties of the enum's
> underlying base type, like size, encoding and signedness.

Well, the enum already has DW_AT_byte_size.  It seems to me that it 
should also have DW_AT_encoding to provide the other two properties you 
mention.

Jason

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-19 20:50                             ` Ping2: " Jason Merrill
@ 2014-05-20  6:55                               ` Mark Wielaard
  2014-05-20 14:43                                 ` Jason Merrill
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-05-20  6:55 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On Mon, May 19, 2014 at 04:50:35PM -0400, Jason Merrill wrote:
> On 05/13/2014 03:21 AM, Mark Wielaard wrote:
> >So the debugger doesn't have to guess the properties of the enum's
> >underlying base type, like size, encoding and signedness.
> 
> Well, the enum already has DW_AT_byte_size.  It seems to me that it should
> also have DW_AT_encoding to provide the other two properties you mention.

Right, that is the idea, since an enum doesn't provide those attributes,
it should have a reference to the underlying base type that provides them.
Then it can also drop the DW_AT_byte_size, if it is different from the
underlying base type, but that is a followup patch.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-20  6:55                               ` Mark Wielaard
@ 2014-05-20 14:43                                 ` Jason Merrill
  2014-05-20 17:51                                   ` Mark Wielaard
  2014-05-20 22:20                                   ` Eric Botcazou
  0 siblings, 2 replies; 29+ messages in thread
From: Jason Merrill @ 2014-05-20 14:43 UTC (permalink / raw)
  To: Mark Wielaard
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On 05/20/2014 02:55 AM, Mark Wielaard wrote:
> On Mon, May 19, 2014 at 04:50:35PM -0400, Jason Merrill wrote:
>> On 05/13/2014 03:21 AM, Mark Wielaard wrote:
>>> So the debugger doesn't have to guess the properties of the enum's
>>> underlying base type, like size, encoding and signedness.
>>
>> Well, the enum already has DW_AT_byte_size.  It seems to me that it should
>> also have DW_AT_encoding to provide the other two properties you mention.
>
> Right, that is the idea, since an enum doesn't provide those attributes,
> it should have a reference to the underlying base type that provides them.

Yes, but why is that better than providing them directly?  The latter 
would seem to work better with non-C-family languages like Ada.

Jason

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-20 14:43                                 ` Jason Merrill
@ 2014-05-20 17:51                                   ` Mark Wielaard
  2014-05-20 19:46                                     ` Jason Merrill
  2014-05-20 22:20                                   ` Eric Botcazou
  1 sibling, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-05-20 17:51 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On Tue, May 20, 2014 at 10:43:22AM -0400, Jason Merrill wrote:
> On 05/20/2014 02:55 AM, Mark Wielaard wrote:
> >On Mon, May 19, 2014 at 04:50:35PM -0400, Jason Merrill wrote:
> >>On 05/13/2014 03:21 AM, Mark Wielaard wrote:
> >>>So the debugger doesn't have to guess the properties of the enum's
> >>>underlying base type, like size, encoding and signedness.
> >>
> >>Well, the enum already has DW_AT_byte_size.  It seems to me that it should
> >>also have DW_AT_encoding to provide the other two properties you mention.
> >
> >Right, that is the idea, since an enum doesn't provide those attributes,
> >it should have a reference to the underlying base type that provides them.
> 
> Yes, but why is that better than providing them directly?

Because that would loose the information of which underlying type
is used to implement the enum. And it is probably less efficient to
replicate all the attributes for each enum. It is also simply how the
DWARF standard specifies these properties. They are not attached to the
DW_TAG_enumeration_type directly but specified through the underlying
type. Which is what gdb expects now.

The DWARF part isn't what this patch is blocked on. That has already
been discussed on the DWARF standard list, coordinated with the gdb
hackers and approved some months ago. The part that hasn't been reviewed
and approved yet is the frontend changes that implement the lang-hook.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-20 17:51                                   ` Mark Wielaard
@ 2014-05-20 19:46                                     ` Jason Merrill
  2014-05-21 13:27                                       ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Jason Merrill @ 2014-05-20 19:46 UTC (permalink / raw)
  To: Mark Wielaard
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On 05/20/2014 01:51 PM, Mark Wielaard wrote:
> The DWARF part isn't what this patch is blocked on. That has already
> been discussed on the DWARF standard list, coordinated with the gdb
> hackers and approved some months ago.

Fair enough.

> The part that hasn't been reviewed
> and approved yet is the frontend changes that implement the lang-hook.

Rather than define the hook for C, let's have a default version that 
uses the type_for_size langhook; that should work better for Ada.

Jason


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-20 14:43                                 ` Jason Merrill
  2014-05-20 17:51                                   ` Mark Wielaard
@ 2014-05-20 22:20                                   ` Eric Botcazou
  1 sibling, 0 replies; 29+ messages in thread
From: Eric Botcazou @ 2014-05-20 22:20 UTC (permalink / raw)
  To: Jason Merrill
  Cc: gcc-patches, Mark Wielaard, Jakub Jelinek, Cary Coutant,
	Tom Tromey, Richard Henderson

> Yes, but why is that better than providing them directly?  The latter
> would seem to work better with non-C-family languages like Ada.

That's correct, enumeration types don't have base types in Ada, i.e. they 
are their own base types.  But if the attributes cannot be expressed in DWARF, 
then synthesizing a base type on the fly would probably be OK.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-20 19:46                                     ` Jason Merrill
@ 2014-05-21 13:27                                       ` Mark Wielaard
  2014-05-21 14:33                                         ` Jason Merrill
  0 siblings, 1 reply; 29+ messages in thread
From: Mark Wielaard @ 2014-05-21 13:27 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 633 bytes --]

On Tue, 2014-05-20 at 15:46 -0400, Jason Merrill wrote:
> Rather than define the hook for C, let's have a default version that 
> uses the type_for_size langhook; that should work better for Ada.

That also makes the patch simpler. Updated patch attached.

Bootstrapped on x86_64-unknown-linux-gnu with --enable-languages=c,c
++,objc,java,ada,fortran and ran against the gdb testsuite without
regressions (there is a tweak needed for one test regexp in
gdb.cp/var-tag.exp to deal with the extra type information, but Tom and
I already discussed on irc this isn't a regression, I'll submit a gdb
testsuite patch asap).

Thanks,

Mark

[-- Attachment #2: 0001-PR-debug-16063.-Add-DW_AT_type-to-DW_TAG_enumeration.patch --]
[-- Type: text/x-patch, Size: 7401 bytes --]

From 6b3fbed4b2bfda22c6e55e151fbaef29c8208c39 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw@redhat.com>
Date: Wed, 21 May 2014 13:00:30 +0200
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. The default implementation will just uses 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.
---
 gcc/ChangeLog       |   14 ++++++++++++++
 gcc/cp/ChangeLog    |    6 ++++++
 gcc/cp/cp-lang.c    |   18 ++++++++++++++++++
 gcc/dwarf2out.c     |    5 +++++
 gcc/langhooks-def.h |    5 ++++-
 gcc/langhooks.c     |    8 ++++++++
 gcc/langhooks.h     |    2 ++
 7 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e2e3dd3..23f7296 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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  Oleg Endo  <olegendo@gcc.gnu.org>
 
 	PR target/54236
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 790b87e..085d0f5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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  Igor Zamyatin  <igor.zamyatin@intel.com>
 
 	PR c/60189
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..6a40d29 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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,19 @@ 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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 4ea05a5..7c93074 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..d9a1dfd 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -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.  */
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index d00ebd8..f6e638d 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -678,3 +678,11 @@ 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));
+}
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..667298b 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -137,6 +137,8 @@ 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);
+
+  tree (*enum_underlying_base_type) (const_tree);
 };
 
 /* Language hooks related to decls and the symbol table.  */
-- 
1.7.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-21 13:27                                       ` Mark Wielaard
@ 2014-05-21 14:33                                         ` Jason Merrill
  2014-05-21 15:49                                           ` Mark Wielaard
  0 siblings, 1 reply; 29+ messages in thread
From: Jason Merrill @ 2014-05-21 14:33 UTC (permalink / raw)
  To: Mark Wielaard
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

On 05/21/2014 09:27 AM, Mark Wielaard wrote:
> +/* 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)

We usually leave a blank line between the comment and the function. 
Also, the function name should be at the beginning of the line for etags.

> +/* Default implementation of enum_underlying_base_type using type_for_size.  */
> +tree
> +lhd_enum_underlying_base_type (const_tree enum_type)

Blank line here, too.

>    tree (*reconstruct_complex_type) (tree, tree);
> +
> +  tree (*enum_underlying_base_type) (const_tree);

And please add a comment documenting the hook.

OK with those changes.

Jason

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Ping2: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.
  2014-05-21 14:33                                         ` Jason Merrill
@ 2014-05-21 15:49                                           ` Mark Wielaard
  0 siblings, 0 replies; 29+ messages in thread
From: Mark Wielaard @ 2014-05-21 15:49 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Jakub Jelinek, Cary Coutant, Tom Tromey, gcc-patches, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

On Wed, 2014-05-21 at 10:33 -0400, Jason Merrill wrote:
> On 05/21/2014 09:27 AM, Mark Wielaard wrote:
> > +/* 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)
> 
> We usually leave a blank line between the comment and the function. 
> Also, the function name should be at the beginning of the line for etags.

Fixed both issues.

> > +/* Default implementation of enum_underlying_base_type using type_for_size.  */
> > +tree
> > +lhd_enum_underlying_base_type (const_tree enum_type)
> 
> Blank line here, too.

Added.

> >    tree (*reconstruct_complex_type) (tree, tree);
> > +
> > +  tree (*enum_underlying_base_type) (const_tree);
> 
> And please add a comment documenting the hook.

Documentation added.

> OK with those changes.

Pushed as attached.

Thanks,

Mark

[-- Attachment #2: 0001-PR-debug-16063.-Add-DW_AT_type-to-DW_TAG_enumeration.patch --]
[-- Type: text/x-patch, Size: 7894 bytes --]

From 1b006e46754125c47544223aa6ee8a42d102fe4d Mon Sep 17 00:00:00 2001
From: mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 21 May 2014 15:44:59 +0000
Subject: [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210717 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog       |   14 ++++++++++++++
 gcc/cp/ChangeLog    |    6 ++++++
 gcc/cp/cp-lang.c    |   20 ++++++++++++++++++++
 gcc/dwarf2out.c     |    5 +++++
 gcc/langhooks-def.h |    5 ++++-
 gcc/langhooks.c     |    9 +++++++++
 gcc/langhooks.h     |    6 ++++++
 7 files changed, 64 insertions(+), 1 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d506727..452b4b0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index adde47f..b0a06b1 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index c28c07a..014f393 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -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"
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 4ea05a5..7c93074 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -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));
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 95bd379..d9a1dfd 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -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.  */
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index d00ebd8..8f65c68 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -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));
+}
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index c848b0c..35b47bc 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -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.  */
-- 
1.7.1


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2014-05-21 15:49 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-23 11:32 [PATCH] PR debug/16063. Add DW_AT_type to DW_TAG_enumeration Mark Wielaard
2014-03-24  9:29 ` Richard Biener
2014-03-24 10:49   ` Mark Wielaard
2014-03-24 17:04 ` Cary Coutant
2014-03-25 10:57   ` Mark Wielaard
2014-03-26 18:53     ` Mark Wielaard
2014-04-10 15:56       ` Tom Tromey
2014-04-10 17:52         ` Cary Coutant
2014-04-11  7:55           ` Mark Wielaard
2014-04-11 18:03             ` Cary Coutant
2014-04-14 21:19               ` Mark Wielaard
2014-04-22 10:33                 ` Ping: " Mark Wielaard
2014-04-28 11:18                   ` Ping2: " Mark Wielaard
2014-04-28 12:37                     ` Jakub Jelinek
2014-04-28 12:44                       ` Mark Wielaard
2014-05-06  7:46                         ` Mark Wielaard
2014-05-13  3:22                         ` Jason Merrill
2014-05-13  7:21                           ` Mark Wielaard
2014-05-19 19:29                             ` Ping4: " Mark Wielaard
2014-05-19 20:50                             ` Ping2: " Jason Merrill
2014-05-20  6:55                               ` Mark Wielaard
2014-05-20 14:43                                 ` Jason Merrill
2014-05-20 17:51                                   ` Mark Wielaard
2014-05-20 19:46                                     ` Jason Merrill
2014-05-21 13:27                                       ` Mark Wielaard
2014-05-21 14:33                                         ` Jason Merrill
2014-05-21 15:49                                           ` Mark Wielaard
2014-05-20 22:20                                   ` Eric Botcazou
2014-05-12  9:39                     ` Ping3: " Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).