This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Emit DW_AT_enum_class attribute for C++0x scoped enums


On Sat, Apr 17, 2010 at 08:14:58PM -0400, Jason Merrill wrote:
> On 04/17/2010 02:40 AM, Jakub Jelinek wrote:
> >I've used ENUM_CLASS_P for the bit macro, because DW_AT_enum_class
> >is the DWARF 4 attribute name and because SCOPED_ENUM_P is already used
> >as macro in cp-tree.h.  I initially thought about moving the 3
> >macros (SCOPED_ENUM_P, UNSCOPED_ENUM_P and SET_SCOPED_ENUM_P) all to
> >tree.h, but I believe e.g. the large, clearly C++ specific, comments
> >probably don't belong to generic tree.h.  The bit macro
> >in tree.h probably could be ENUM_IS_SCOPED_P or something similar.
> 
> Let's go with ENUM_IS_SCOPED.  It seems redundant to have both _IS_ and _P.

Ok, here is what I've committed:

2010-04-19  Jakub Jelinek  <jakub@redhat.com>

	* tree.h (ENUM_IS_SCOPED): Define.
	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_enum_class
	for ENUM_IS_SCOPED enums.
cp/
	* cp-tree.h (SCOPED_ENUM_P, UNSCOPED_ENUM_P, SET_SCOPED_ENUM_P): Use
	ENUM_IS_SCOPED bit instead of TYPE_LANG_FLAG_5.
testsuite/
	* g++.dg/debug/dwarf2/enum1.C: New test.

--- gcc/cp/cp-tree.h.jj	2010-04-16 17:35:36.000000000 +0200
+++ gcc/cp/cp-tree.h	2010-04-16 20:44:25.000000000 +0200
@@ -121,7 +121,6 @@ framework extensions, you must include t
    3: TYPE_FOR_JAVA.
    4: TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    5: CLASS_TYPE_P (in RECORD_TYPE and UNION_TYPE)
-      SCOPED_ENUM_P (in ENUMERAL_TYPE)
    6: TYPE_DEPENDENT_P_VALID
 
    Usage of DECL_LANG_FLAG_?:
@@ -3036,17 +3035,17 @@ more_aggr_init_expr_args_p (const aggr_i
 
      - The underlying type of the enum is well-defined.  */
 #define SCOPED_ENUM_P(TYPE)                                             \
-  (TREE_CODE (TYPE) == ENUMERAL_TYPE && TYPE_LANG_FLAG_5 (TYPE))
+  (TREE_CODE (TYPE) == ENUMERAL_TYPE && ENUM_IS_SCOPED (TYPE))
 
 /* Determine whether this is an unscoped enumeration type.  */
 #define UNSCOPED_ENUM_P(TYPE)                                           \
-  (TREE_CODE (TYPE) == ENUMERAL_TYPE && !TYPE_LANG_FLAG_5 (TYPE))
+  (TREE_CODE (TYPE) == ENUMERAL_TYPE && !ENUM_IS_SCOPED (TYPE))
 
 /* Set the flag indicating whether an ENUMERAL_TYPE is a C++0x scoped
    enumeration type (1) or a normal (unscoped) enumeration type
    (0).  */
 #define SET_SCOPED_ENUM_P(TYPE, VAL)                    \
-  (TYPE_LANG_FLAG_5 (ENUMERAL_TYPE_CHECK (TYPE)) = (VAL))
+  (ENUM_IS_SCOPED (TYPE) = (VAL))
 
 /* Returns the underlying type of the given enumeration type. The
    underlying type is determined in different ways, depending on the
--- gcc/dwarf2out.c.jj	2010-04-16 17:37:31.000000000 +0200
+++ gcc/dwarf2out.c	2010-04-16 20:44:52.000000000 +0200
@@ -17385,6 +17385,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)
+	  && ENUM_IS_SCOPED (type))
+	add_AT_flag (type_die, DW_AT_enum_class, 1);
     }
   else if (! TYPE_SIZE (type))
     return type_die;
--- gcc/tree.h.jj	2010-04-16 20:35:56.000000000 +0200
+++ gcc/tree.h	2010-04-16 20:43:30.000000000 +0200
@@ -457,6 +457,9 @@ struct GTY(()) tree_common {
 
        CALL_CANNOT_INLINE_P in
            CALL_EXPR
+ 
+       ENUM_IS_SCOPED in
+	   ENUMERAL_TYPE
 
    public_flag:
 
@@ -1162,6 +1165,9 @@ extern void omp_clause_range_check_faile
 /* Used to mark a CALL_EXPR as not suitable for inlining.  */
 #define CALL_CANNOT_INLINE_P(NODE) (CALL_EXPR_CHECK (NODE)->base.static_flag)
 
+/* Used to mark scoped enums.  */
+#define ENUM_IS_SCOPED(NODE) (ENUMERAL_TYPE_CHECK (NODE)->base.static_flag)
+
 /* In an expr node (usually a conversion) this means the node was made
    implicitly and should not lead to any sort of warning.  In a decl node,
    warnings concerning the decl should be suppressed.  This is used at
--- gcc/testsuite/g++.dg/debug/dwarf2/enum1.C.jj	2010-04-16 20:40:15.000000000 +0200
+++ gcc/testsuite/g++.dg/debug/dwarf2/enum1.C	2010-04-16 20:40:15.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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]