This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Emit DW_AT_enum_class attribute for C++0x scoped enums
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Dodji Seketeli <dodji at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Apr 2010 16:26:13 +0200
- Subject: [PATCH] Emit DW_AT_enum_class attribute for C++0x scoped enums
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
DWARF4 adds a new DW_AT_enum_class attribute, a flag that should be set on
DW_TAG_enumeration_type for scoped enums, so that debuggers can restrict the
enumerators only to ENUM::enumx form.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2010-04-16 Jakub Jelinek <jakub@redhat.com>
* langhooks-def.h (struct lang_hooks_for_types): Add scoped_enum_p
field.
* langhooks-def.h (LANG_HOOKS_SCOPED_ENUM_P): Define.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add it.
* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_enum_class
for scoped enums.
cp/
* cp-tree.h (cxx_scoped_enum_p): New prototype.
* cp-objcp-common.h (LANG_HOOKS_SCOPED_ENUM_P): Redefine.
* cp-objcp-common.c (cxx_scoped_enum_p): New function.
testsuite/
* g++.dg/debug/dwarf2/enum1.C: New test.
--- gcc/langhooks.h.jj 2009-11-30 15:53:27.000000000 +0100
+++ gcc/langhooks.h 2010-04-16 12:13:43.000000000 +0200
@@ -1,5 +1,5 @@
/* The lang_hooks data structure.
- Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GCC.
@@ -76,6 +76,9 @@ struct lang_hooks_for_types
be structures. */
enum classify_record (*classify_record) (tree);
+ /* Return true if an ENUMERAL_TYPE is scoped, false if it is not. */
+ bool (*scoped_enum_p) (const_tree);
+
/* Given MODE and UNSIGNEDP, return a suitable type-tree with that
mode. */
tree (*type_for_mode) (enum machine_mode, int);
--- gcc/langhooks-def.h.jj 2009-11-30 15:53:27.000000000 +0100
+++ gcc/langhooks-def.h 2010-04-16 12:16:44.000000000 +0200
@@ -1,5 +1,5 @@
/* Default macros to initialize the lang_hooks data structure.
- Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
Free Software Foundation, Inc.
Contributed by Alexandre Oliva <aoliva@redhat.com>
@@ -152,6 +152,7 @@ extern tree lhd_make_node (enum tree_cod
so we create a compile-time error instead. */
#define LANG_HOOKS_MAKE_TYPE lhd_make_node
#define LANG_HOOKS_CLASSIFY_RECORD NULL
+#define LANG_HOOKS_SCOPED_ENUM_P hook_bool_const_tree_false
#define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
#define LANG_HOOKS_GENERIC_TYPE_P hook_bool_const_tree_false
#define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS hook_tree_const_tree_null
@@ -176,6 +177,7 @@ extern tree lhd_make_node (enum tree_cod
#define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
LANG_HOOKS_MAKE_TYPE, \
LANG_HOOKS_CLASSIFY_RECORD, \
+ LANG_HOOKS_SCOPED_ENUM_P, \
LANG_HOOKS_TYPE_FOR_MODE, \
LANG_HOOKS_TYPE_FOR_SIZE, \
LANG_HOOKS_GENERIC_TYPE_P, \
--- gcc/dwarf2out.c.jj 2010-04-16 09:26:23.000000000 +0200
+++ gcc/dwarf2out.c 2010-04-16 12:58:21.000000000 +0200
@@ -17377,6 +17377,9 @@ gen_enumeration_type_die (tree type, dw_
scope_die_for (type, context_die), type);
equate_type_number_to_die (type, type_die);
add_name_attribute (type_die, type_tag (type));
+ if ((dwarf_version >= 4 || !dwarf_strict)
+ && lang_hooks.types.scoped_enum_p (type))
+ add_AT_flag (type_die, DW_AT_enum_class, 1);
}
else if (! TYPE_SIZE (type))
return type_die;
--- gcc/cp/cp-tree.h.jj 2010-04-13 14:16:38.000000000 +0200
+++ gcc/cp/cp-tree.h 2010-04-16 12:19:27.000000000 +0200
@@ -5472,6 +5472,7 @@ extern bool cp_var_mod_type_p (tree, t
extern void cxx_initialize_diagnostics (struct diagnostic_context *);
extern int cxx_types_compatible_p (tree, tree);
extern void init_shadowed_var_for_decl (void);
+extern bool cxx_scoped_enum_p (const_tree);
/* in cp-gimplify.c */
extern int cp_gimplify_expr (tree *, gimple_seq *,
--- gcc/cp/cp-objcp-common.h.jj 2009-11-30 15:53:13.000000000 +0100
+++ gcc/cp/cp-objcp-common.h 2010-04-16 12:18:09.000000000 +0200
@@ -1,5 +1,6 @@
/* Language hooks common to C++ and ObjC++ front ends.
- Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Ziemowit Laski <zlaski@apple.com>
This file is part of GCC.
@@ -111,6 +112,8 @@ extern bool cp_function_decl_explicit_p
#define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
#undef LANG_HOOKS_TYPE_FOR_SIZE
#define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
+#undef LANG_HOOKS_SCOPED_ENUM_P
+#define LANG_HOOKS_SCOPED_ENUM_P cxx_scoped_enum_p
#undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
#define LANG_HOOKS_INCOMPLETE_TYPE_ERROR cxx_incomplete_type_error
#undef LANG_HOOKS_TYPE_PROMOTES_TO
--- gcc/cp/cp-objcp-common.c.jj 2010-02-19 09:23:09.000000000 +0100
+++ gcc/cp/cp-objcp-common.c 2010-04-16 12:20:32.000000000 +0200
@@ -1,5 +1,5 @@
/* Some code common to C++ and ObjC++ front ends.
- Copyright (C) 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Contributed by Ziemowit Laski <zlaski@apple.com>
This file is part of GCC.
@@ -159,6 +159,14 @@ cp_function_decl_explicit_p (tree decl)
&& DECL_NONCONVERTING_P (decl));
}
+/* Return true if TYPE is a scoped enum. */
+
+bool
+cxx_scoped_enum_p (const_tree type)
+{
+ return SCOPED_ENUM_P (type);
+}
+
/* Stubs to keep c-opts.c happy. */
void
push_file_scope (void)
--- gcc/testsuite/g++.dg/debug/dwarf2/enum1.C.jj 2010-04-16 13:01:02.000000000 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/enum1.C 2010-04-16 13:04:33.000000000 +0200
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-g -dA -gno-strict-dwarf -std=c++0x" }
+// { dg-final { scan-assembler-times "DIE\[^\n\r\]*DW_TAG_enumeration_type" 3 } }
+// { dg-final { scan-assembler-times " DW_AT_enum_class" 2 } }
+
+enum A { a1, a2 } a;
+enum struct B { b1, b2 } b;
+enum class C { c1, c2 } c;
+
+void
+foo ()
+{
+ a = a1;
+ a = A::a2;
+ b = B::b1;
+ b = B::b2;
+ c = C::c1;
+ c = C::c2;
+}
Jakub