[C++] anon type names
diff mbox series

Message ID 06870cd2-7866-8feb-2325-508803535a51@acm.org
State New
Headers show
Series
  • [C++] anon type names
Related show

Commit Message

Nathan Sidwell Oct. 18, 2019, 12:44 p.m. UTC
I noticed that we use a bitfield flag to note types with names for 
linkage purposes:
   typedef struct {} foo;
but, we can infer this by comparing TYPE_STUB_DECL and TYPE_DECL of the 
main variant.  It's only checked in two places -- the C++ parser and the 
objective C++ encoder.

Committing this to trunk.

nathan

Patch
diff mbox series

2019-10-18  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (struct lang_type): Remove was_anonymous.
	(TYPE_WAS_UNNAMED): Implement by checking TYPE_DECL &
	TYPE_STUB_DECL.
	* decl.c (name_unnamed_type): Don't set TYPE_WAS_UNNAMED.

Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 277149)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -2153,5 +2153,4 @@  struct GTY(()) lang_type {
   unsigned ptrmemfunc_flag : 1;
 
-  unsigned was_anonymous : 1;
   unsigned lazy_default_ctor : 1;
   unsigned lazy_copy_ctor : 1;
@@ -2161,6 +2160,6 @@  struct GTY(()) lang_type {
   unsigned has_complex_copy_ctor : 1;
   unsigned has_complex_copy_assign : 1;
-
   unsigned non_aggregate : 1;
+
   unsigned has_complex_dflt : 1;
   unsigned has_list_ctor : 1;
@@ -2170,6 +2169,6 @@  struct GTY(()) lang_type {
   unsigned lazy_move_assign : 1;
   unsigned has_complex_move_ctor : 1;
-
   unsigned has_complex_move_assign : 1;
+
   unsigned has_constexpr_ctor : 1;
   unsigned unique_obj_representations : 1;
@@ -2183,5 +2182,5 @@  struct GTY(()) lang_type {
      of this by updating the size of this bitfield whenever you add or
      remove a flag.  */
-  unsigned dummy : 4;
+  unsigned dummy : 5;
 
   tree primary_base;
@@ -4586,6 +4585,10 @@  more_aggr_init_expr_args_p (const aggr_i
 /* Define fields and accessors for nodes representing declared names.  */
 
-/* Nonzero if TYPE is an unnamed class with a typedef for linkage purposes.  */
-#define TYPE_WAS_UNNAMED(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->was_anonymous)
+/* True if TYPE is an unnamed structured type with a typedef for
+   linkage purposes.  In that case TYPE_NAME and TYPE_STUB_DECL of the
+   MAIN-VARIANT are different. */
+#define TYPE_WAS_UNNAMED(NODE)				\
+  (TYPE_NAME (TYPE_MAIN_VARIANT (NODE))			\
+   != TYPE_STUB_DECL (TYPE_MAIN_VARIANT (NODE)))
 
 /* C++: all of these are overloaded!  These apply only to TYPE_DECLs.  */
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 277149)
+++ gcc/cp/decl.c	(working copy)
@@ -10442,7 +10442,4 @@  name_unnamed_type (tree type, tree decl)
       TYPE_NAME (t) = decl;
 
-  if (TYPE_LANG_SPECIFIC (type))
-    TYPE_WAS_UNNAMED (type) = 1;
-
   /* If this is a typedef within a template class, the nested
      type is a (non-primary) template.  The name for the