public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2615] d: Use hasMonitor to determine whether to emit a __monitor field in D classes
@ 2021-07-30 10:55 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-30 10:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bc5208f7357bfe8e466890a4c856a642cc16920f

commit r12-2615-gbc5208f7357bfe8e466890a4c856a642cc16920f
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Jul 26 17:31:40 2021 +0200

    d: Use hasMonitor to determine whether to emit a __monitor field in D classes
    
    This helper introduced by the front-end is a better gate, and allows the
    front-end to change rules for what gets a monitor in the future.
    
    gcc/d/ChangeLog:
    
            * types.cc (layout_aggregate_type): Call hasMonitor.
            * typeinfo.cc (TypeInfoVisitor::layout_base): Likewise.
            (layout_cpp_typeinfo): Likewise.  Don't emit vtable unless
            have_typeinfo_p.

Diff:
---
 gcc/d/typeinfo.cc | 21 ++++++++++++++-------
 gcc/d/types.cc    |  2 +-
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index a1f0543d58e..c9126f4c6b5 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -423,7 +423,8 @@ class TypeInfoVisitor : public Visitor
     else
       this->layout_field (null_pointer_node);
 
-    this->layout_field (null_pointer_node);
+    if (cd->hasMonitor ())
+      this->layout_field (null_pointer_node);
   }
 
   /* Write out the interfaces field of class CD.
@@ -1457,9 +1458,17 @@ layout_cpp_typeinfo (ClassDeclaration *cd)
   /* Use the vtable of __cpp_type_info_ptr, the EH personality routine
      expects this, as it uses .classinfo identity comparison to test for
      C++ catch handlers.  */
-  tree vptr = get_vtable_decl (ClassDeclaration::cpp_type_info_ptr);
-  CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, build_address (vptr));
-  CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, null_pointer_node);
+  ClassDeclaration *cppti = ClassDeclaration::cpp_type_info_ptr;
+  if (have_typeinfo_p (cppti))
+    {
+      tree vptr = get_vtable_decl (cppti);
+      CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, build_address (vptr));
+    }
+  else
+    CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, null_pointer_node);
+
+  if (cppti->hasMonitor ())
+    CONSTRUCTOR_APPEND_ELT (init, NULL_TREE, null_pointer_node);
 
   /* Let C++ do the RTTI generation, and just reference the symbol as
      extern, knowing the underlying type is not required.  */
@@ -1471,9 +1480,7 @@ layout_cpp_typeinfo (ClassDeclaration *cd)
 
   /* Build the initializer and emit.  */
   DECL_INITIAL (decl) = build_struct_literal (TREE_TYPE (decl), init);
-  DECL_EXTERNAL (decl) = 0;
-  d_pushdecl (decl);
-  rest_of_decl_compilation (decl, 1, 0);
+  d_finish_decl (decl);
 }
 
 /* Get the VAR_DECL of the __cpp_type_info_ptr for DECL.  If this does not yet
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index ba2d6d4dc66..8e674618004 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -469,7 +469,7 @@ layout_aggregate_type (AggregateDeclaration *decl, tree type,
 	      insert_aggregate_field (type, field, 0);
 	    }
 
-	  if (!id && !cd->isCPPclass ())
+	  if (!id && cd->hasMonitor ())
 	    {
 	      tree field = create_field_decl (ptr_type_node, "__monitor", 1,
 					      inherited_p);


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

only message in thread, other threads:[~2021-07-30 10:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 10:55 [gcc r12-2615] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw

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