public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* c++: Name as_base type
@ 2020-07-22 19:06 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-07-22 19:06 UTC (permalink / raw)
  To: GCC Patches

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

The as-base type never got a name.  For modules I needed to give it a 
name to serialize properly, and it's useful when debugging the compiler, 
so we may as well have it on trunk.  There's also a bug where its fields 
can have NSDMIs from the main class.  This happens to be silent on 
trunk, but can be a GC leak where we retain a deferred parse node there. 
(On modules it blows up, because we're not prepared to serialize 
deferred parse nodes, as they should never survive parsing.

             gcc/cp/
             * cp-tree.h (enum cp_tree_index): Add CPTI_AS_BASE_IDENTIFIER.
             (as_base_identifier): Define.
             * decl.c (initialize_predifined_identifiers): Initialize 
as_base
             identifier.
             * class.c (layout_class_type): Name the as-base type.  Zap
             NSDMI its fields may have.

-- 
Nathan Sidwell

[-- Attachment #2: as-base.diff --]
[-- Type: text/x-patch, Size: 2696 bytes --]

diff --git i/gcc/cp/class.c w/gcc/cp/class.c
index a3913f4ce0b..ba96113bc88 100644
--- i/gcc/cp/class.c
+++ w/gcc/cp/class.c
@@ -6715,6 +6715,10 @@ layout_class_type (tree t, tree *virtuals_p)
       /* T needs a different layout as a base (eliding virtual bases
 	 or whatever).  Create that version.  */
       tree base_t = make_node (TREE_CODE (t));
+      tree base_d = create_implicit_typedef (as_base_identifier, base_t);
+
+      TYPE_CONTEXT (base_t) = t;
+      DECL_CONTEXT (base_d) = t;
 
       /* If the ABI version is not at least two, and the last
 	 field was a bit-field, RLI may not be on a byte
@@ -6751,6 +6755,9 @@ layout_class_type (tree t, tree *virtuals_p)
 	if (TREE_CODE (field) == FIELD_DECL)
 	  {
 	    *next_field = copy_node (field);
+	    /* Zap any NSDMI, it's not needed and might be a deferred
+	       parse.  */
+	    DECL_INITIAL (*next_field) = NULL_TREE;
 	    DECL_CONTEXT (*next_field) = base_t;
 	    next_field = &DECL_CHAIN (*next_field);
 	  }
@@ -6760,8 +6767,6 @@ layout_class_type (tree t, tree *virtuals_p)
 	 needs a mode.  */
       compute_record_mode (base_t);
 
-      TYPE_CONTEXT (base_t) = t;
-
       /* Record the base version of the type.  */
       CLASSTYPE_AS_BASE (t) = base_t;
     }
diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h
index d43c53ae29a..2377fc052bb 100644
--- i/gcc/cp/cp-tree.h
+++ w/gcc/cp/cp-tree.h
@@ -148,6 +148,7 @@ enum cp_tree_index
     CPTI_DELTA_IDENTIFIER,
     CPTI_IN_CHARGE_IDENTIFIER,
     CPTI_VTT_PARM_IDENTIFIER,
+    CPTI_AS_BASE_IDENTIFIER,
     CPTI_THIS_IDENTIFIER,
     CPTI_PFN_IDENTIFIER,
     CPTI_VPTR_IDENTIFIER,
@@ -289,6 +290,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
 /* The name of the parameter that contains a pointer to the VTT to use
    for this subobject constructor or destructor.  */
 #define vtt_parm_identifier		cp_global_trees[CPTI_VTT_PARM_IDENTIFIER]
+#define as_base_identifier		cp_global_trees[CPTI_AS_BASE_IDENTIFIER]
 #define this_identifier			cp_global_trees[CPTI_THIS_IDENTIFIER]
 #define pfn_identifier			cp_global_trees[CPTI_PFN_IDENTIFIER]
 #define vptr_identifier			cp_global_trees[CPTI_VPTR_IDENTIFIER]
diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c
index de53a7b8b73..385b1f3a0c4 100644
--- i/gcc/cp/decl.c
+++ w/gcc/cp/decl.c
@@ -4202,6 +4202,7 @@ initialize_predefined_identifiers (void)
     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
     {"__conv_op ", &conv_op_identifier, cik_conv_op},
     {"__in_chrg", &in_charge_identifier, cik_normal},
+    {"__as_base ", &as_base_identifier, cik_normal},
     {"this", &this_identifier, cik_normal},
     {"__delta", &delta_identifier, cik_normal},
     {"__pfn", &pfn_identifier, cik_normal},

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-22 19:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 19:06 c++: Name as_base type Nathan Sidwell

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).