public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function.
@ 2021-07-30 11:01 Iain Buclaw
  2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

Both do the exact same operation, just on different AST nodes.

gcc/d/ChangeLog:

	* d-codegen.cc (d_nested_class): Rename to ...
	(get_outer_function): ... this.  Handle all aggregate declarations.
	(d_nested_struct): Remove.
	(find_this_tree): Use get_outer_function.
	(get_framedecl): Likewise.
---
 gcc/d/d-codegen.cc | 54 ++++++++++++----------------------------------
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index f35de90b54c..fe2ad98e60a 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2354,41 +2354,24 @@ get_frame_for_symbol (Dsymbol *sym)
   return null_pointer_node;
 }
 
-/* Return the parent function of a nested class CD.  */
+/* Return the parent function of a nested class or struct AD.  */
 
 static FuncDeclaration *
-d_nested_class (ClassDeclaration *cd)
+get_outer_function (AggregateDeclaration *ad)
 {
   FuncDeclaration *fd = NULL;
-  while (cd && cd->isNested ())
+  while (ad && ad->isNested ())
     {
-      Dsymbol *dsym = cd->toParent2 ();
+      Dsymbol *dsym = ad->toParent2 ();
       if ((fd = dsym->isFuncDeclaration ()))
 	return fd;
       else
-	cd = dsym->isClassDeclaration ();
+	ad = dsym->isAggregateDeclaration ();
     }
-  return NULL;
-}
-
-/* Return the parent function of a nested struct SD.  */
 
-static FuncDeclaration *
-d_nested_struct (StructDeclaration *sd)
-{
-  FuncDeclaration *fd = NULL;
-  while (sd && sd->isNested ())
-    {
-      Dsymbol *dsym = sd->toParent2 ();
-      if ((fd = dsym->isFuncDeclaration ()))
-	return fd;
-      else
-	sd = dsym->isStructDeclaration ();
-    }
   return NULL;
 }
 
-
 /* Starting from the current function FD, try to find a suitable value of
    `this' in nested function instances.  A suitable `this' value is an
    instance of OCD or a class that has OCD as a base.  */
@@ -2411,18 +2394,17 @@ find_this_tree (ClassDeclaration *ocd)
 	    return convert_expr (get_decl_tree (fd->vthis),
 				 cd->type, ocd->type);
 
-	  fd = d_nested_class (cd);
+	  fd = get_outer_function (cd);
+	  continue;
 	}
-      else
-	{
-	  if (fd->isNested ())
-	    {
-	      fd = fd->toParent2 ()->isFuncDeclaration ();
-	      continue;
-	    }
 
-	  fd = NULL;
+      if (fd->isNested ())
+	{
+	  fd = fd->toParent2 ()->isFuncDeclaration ();
+	  continue;
 	}
+
+      fd = NULL;
     }
 
   return NULL_TREE;
@@ -2760,10 +2742,6 @@ get_framedecl (FuncDeclaration *inner, FuncDeclaration *outer)
 
   while (fd && fd != outer)
     {
-      AggregateDeclaration *ad;
-      ClassDeclaration *cd;
-      StructDeclaration *sd;
-
       /* Parent frame link is the first field.  */
       if (FRAMEINFO_CREATES_FRAME (get_frameinfo (fd)))
 	result = indirect_ref (ptr_type_node, result);
@@ -2773,12 +2751,8 @@ get_framedecl (FuncDeclaration *inner, FuncDeclaration *outer)
       /* The frame/closure record always points to the outer function's
 	 frame, even if there are intervening nested classes or structs.
 	 So, we can just skip over these.  */
-      else if ((ad = fd->isThis ()) && (cd = ad->isClassDeclaration ()))
-	fd = d_nested_class (cd);
-      else if ((ad = fd->isThis ()) && (sd = ad->isStructDeclaration ()))
-	fd = d_nested_struct (sd);
       else
-	break;
+	fd = get_outer_function (fd->isThis ());
     }
 
   if (fd != outer)
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 03/12] d: Insert null terminator in obstack buffers Iain Buclaw
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

This ensures there are no dangling references to AST members that have
been freed, either explcitly or by the garbage collector.

gcc/d/ChangeLog:

	* d-builtins.cc (build_frontend_type): Restore builtin_converted_decls
	length on conversion failure.
---
 gcc/d/d-builtins.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index ff2a5776dc5..9db46c0c5ca 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -80,7 +80,8 @@ build_frontend_type (tree type)
     mod |= MODshared;
 
   /* If we've seen the type before, re-use the converted decl.  */
-  for (size_t i = 0; i < builtin_converted_decls.length (); ++i)
+  unsigned saved_builtin_decls_length = builtin_converted_decls.length ();
+  for (size_t i = 0; i < saved_builtin_decls_length; ++i)
     {
       tree t = builtin_converted_decls[i].ctype;
       if (TYPE_MAIN_VARIANT (t) == TYPE_MAIN_VARIANT (type))
@@ -249,6 +250,9 @@ build_frontend_type (tree type)
 	  Type *ftype = build_frontend_type (TREE_TYPE (field));
 	  if (!ftype)
 	    {
+	      /* Drop any field types that got cached before the conversion
+		 of this record type failed.  */
+	      builtin_converted_decls.truncate (saved_builtin_decls_length);
 	      delete sdecl->members;
 	      return NULL;
 	    }
@@ -307,6 +311,9 @@ build_frontend_type (tree type)
 	      Type *targ = build_frontend_type (argtype);
 	      if (!targ)
 		{
+		  /* Drop any parameter types that got cached before the
+		     conversion of this function type failed.  */
+		  builtin_converted_decls.truncate (saved_builtin_decls_length);
 		  delete args;
 		  return NULL;
 		}
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 03/12] d: Insert null terminator in obstack buffers
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
  2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-11-25 14:09   ` Martin Liška
  2021-07-30 11:01 ` [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

Covers cases where functions that handle the extracted strings ignore
the explicit length.  This isn't something that's known to happen in the
current front-end, but the self-hosted front-end has been observed to do
this in its conversions between D and C-style strings.

gcc/d/ChangeLog:

	* d-lang.cc (deps_add_target): Insert null terminator in buffer.
	(deps_write): Likewise.
	(d_parse_file): Likewise.
---
 gcc/d/d-lang.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index ac0945b1f34..4386a489ff2 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -108,7 +108,7 @@ deps_add_target (const char *target, bool quoted)
 
   if (!quoted)
     {
-      obstack_grow (&buffer, target, strlen (target));
+      obstack_grow0 (&buffer, target, strlen (target));
       d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
       return;
     }
@@ -149,6 +149,7 @@ deps_add_target (const char *target, bool quoted)
       obstack_1grow (&buffer, *p);
     }
 
+  obstack_1grow (&buffer, '\0');
   d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
 }
 
@@ -278,6 +279,8 @@ deps_write (Module *module, obstack *buffer)
       obstack_grow (buffer, str, strlen (str));
       obstack_grow (buffer, ":\n", 2);
     }
+
+  obstack_1grow (buffer, '\0');
 }
 
 /* Implements the lang_hooks.init_options routine for language D.
@@ -884,6 +887,7 @@ d_parse_file (void)
 	      obstack_grow (&buffer, str, strlen (str));
 	    }
 
+	  obstack_1grow (&buffer, '\0');
 	  message ("%s", (char *) obstack_finish (&buffer));
 	}
     }
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
  2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
  2021-07-30 11:01 ` [committed 03/12] d: Insert null terminator in obstack buffers Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 05/12] d: Use Identifier::idPool to generate anonymous field name Iain Buclaw
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 05/12] d: Use Identifier::idPool to generate anonymous field name.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (2 preceding siblings ...)
  2021-07-30 11:01 ` [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations Iain Buclaw
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

The self-hosted implementation of the D front-end does not export
Identifier::generateId, so handle name generation inline instead.

gcc/d/ChangeLog:

	* d-builtins.cc (build_frontend_type): Use Identifier::idPool to
	generate anonymous field name.
---
 gcc/d/d-builtins.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 9db46c0c5ca..328711fc745 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -241,8 +241,8 @@ build_frontend_type (tree type)
       sdecl->type->merge2 ();
 
       /* Add both named and anonymous fields as members of the struct.
-	 Anonymous fields still need a name in D, so call them "__pad%d".  */
-      int anonfield_id = 0;
+	 Anonymous fields still need a name in D, so call them "__pad%u".  */
+      unsigned anonfield_id = 0;
       sdecl->members = new Dsymbols;
 
       for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
@@ -259,7 +259,11 @@ build_frontend_type (tree type)
 
 	  Identifier *fident;
 	  if (DECL_NAME (field) == NULL_TREE)
-	    fident = Identifier::generateId ("__pad", anonfield_id++);
+	    {
+	      char name[16];
+	      snprintf (name, sizeof (name), "__pad%u", anonfield_id++);
+	      fident = Identifier::idPool (name);
+	    }
 	  else
 	    {
 	      const char *name = IDENTIFIER_POINTER (DECL_NAME (field));
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (3 preceding siblings ...)
  2021-07-30 11:01 ` [committed 05/12] d: Use Identifier::idPool to generate anonymous field name Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public Iain Buclaw
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

The self-hosted implementation of the D front-end changes the type of
`sinit' to a void pointer, which requires an explicit cast to `tree'.

gcc/d/ChangeLog:

	* decl.cc (DeclVisitor::visit (StructDeclaration *)): Don't use sinit
	for declaration directly.
	(DeclVisitor::visit (ClassDeclaration *)): Likewise.
	(aggregate_initializer_decl): Likewise.  Set sinit after creating.
---
 gcc/d/decl.cc | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 7d1378255bd..59991c3c255 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -386,9 +386,9 @@ public:
       create_typeinfo (d->type, NULL);
 
     /* Generate static initializer.  */
-    d->sinit = aggregate_initializer_decl (d);
-    DECL_INITIAL (d->sinit) = layout_struct_initializer (d);
-    d_finish_decl (d->sinit);
+    tree sinit = aggregate_initializer_decl (d);
+    DECL_INITIAL (sinit) = layout_struct_initializer (d);
+    d_finish_decl (sinit);
 
     /* Put out the members.  There might be static constructors in the members
        list, and they cannot be put in separate object files.  */
@@ -496,11 +496,11 @@ public:
     /* Generate C symbols.  */
     d->csym = get_classinfo_decl (d);
     d->vtblsym = get_vtable_decl (d);
-    d->sinit = aggregate_initializer_decl (d);
+    tree sinit = aggregate_initializer_decl (d);
 
     /* Generate static initializer.  */
-    DECL_INITIAL (d->sinit) = layout_class_initializer (d);
-    d_finish_decl (d->sinit);
+    DECL_INITIAL (sinit) = layout_class_initializer (d);
+    d_finish_decl (sinit);
 
     /* Put out the TypeInfo.  */
     if (have_typeinfo_p (Type::dtypeinfo))
@@ -2151,7 +2151,7 @@ tree
 aggregate_initializer_decl (AggregateDeclaration *decl)
 {
   if (decl->sinit)
-    return decl->sinit;
+    return (tree) decl->sinit;
 
   /* Class is a reference, want the record type.  */
   tree type = build_ctype (decl->type);
@@ -2161,20 +2161,21 @@ aggregate_initializer_decl (AggregateDeclaration *decl)
 
   tree ident = mangle_internal_decl (decl, "__init", "Z");
 
-  decl->sinit = declare_extern_var (ident, type);
-  DECL_LANG_SPECIFIC (decl->sinit) = build_lang_decl (NULL);
+  tree sinit = declare_extern_var (ident, type);
+  DECL_LANG_SPECIFIC (sinit) = build_lang_decl (NULL);
 
-  DECL_CONTEXT (decl->sinit) = type;
-  TREE_READONLY (decl->sinit) = 1;
+  DECL_CONTEXT (sinit) = type;
+  TREE_READONLY (sinit) = 1;
 
   /* Honor struct alignment set by user.  */
   if (sd && sd->alignment != STRUCTALIGN_DEFAULT)
     {
-      SET_DECL_ALIGN (decl->sinit, sd->alignment * BITS_PER_UNIT);
-      DECL_USER_ALIGN (decl->sinit) = true;
+      SET_DECL_ALIGN (sinit, sd->alignment * BITS_PER_UNIT);
+      DECL_USER_ALIGN (sinit) = true;
     }
 
-  return decl->sinit;
+  decl->sinit = sinit;
+  return sinit;
 }
 
 /* Generate the data for the static initializer.  */
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (4 preceding siblings ...)
  2021-07-30 11:01 ` [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 08/12] d: Only handle named enums in enum_initializer_decl Iain Buclaw
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

It is not expected to have a member function that can be non-public, but
this guards against any internal errors that might occur should that
ever change in the front-end.

gcc/d/ChangeLog:

	* decl.cc (make_thunk): Set COMDAT and visibility of thunks only if
	they are public.
---
 gcc/d/decl.cc | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 59991c3c255..cf61cd49159 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -1781,9 +1781,12 @@ make_thunk (FuncDeclaration *decl, int offset)
   DECL_ARTIFICIAL (thunk) = 1;
   DECL_DECLARED_INLINE_P (thunk) = 0;
 
-  DECL_VISIBILITY (thunk) = DECL_VISIBILITY (function);
-  DECL_COMDAT (thunk) = DECL_COMDAT (function);
-  DECL_WEAK (thunk) = DECL_WEAK (function);
+  if (TREE_PUBLIC (thunk))
+    {
+      DECL_VISIBILITY (thunk) = DECL_VISIBILITY (function);
+      DECL_COMDAT (thunk) = DECL_COMDAT (function);
+      DECL_WEAK (thunk) = DECL_WEAK (function);
+    }
 
   /* When the thunk is for an extern C++ function, let C++ do the thunk
      generation and just reference the symbol as extern, instead of
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 08/12] d: Only handle named enums in enum_initializer_decl
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (5 preceding siblings ...)
  2021-07-30 11:01 ` [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 09/12] d: Clarify comment for generating static array assignment with literal Iain Buclaw
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

Anonymous enums neither generate an initializer nor typeinfo symbol, so
it's safe to assert that all enum declarations passed to this function
always have an identifier.

gcc/d/ChangeLog:

	* decl.cc (enum_initializer_decl): Only handle named enums.
---
 gcc/d/decl.cc | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index cf61cd49159..0d46ee180e7 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -2218,13 +2218,10 @@ enum_initializer_decl (EnumDeclaration *decl)
   if (decl->sinit)
     return decl->sinit;
 
-  tree type = build_ctype (decl->type);
+  gcc_assert (decl->ident);
 
-  Identifier *ident_save = decl->ident;
-  if (!decl->ident)
-    decl->ident = Identifier::generateId ("__enum");
+  tree type = build_ctype (decl->type);
   tree ident = mangle_internal_decl (decl, "__init", "Z");
-  decl->ident = ident_save;
 
   decl->sinit = declare_extern_var (ident, type);
   DECL_LANG_SPECIFIC (decl->sinit) = build_lang_decl (NULL);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 09/12] d: Clarify comment for generating static array assignment with literal.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (6 preceding siblings ...)
  2021-07-30 11:01 ` [committed 08/12] d: Only handle named enums in enum_initializer_decl Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off Iain Buclaw
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

The code block is done as an optimization to elide a call to the runtime
library helpers _d_arrayctor or _d_arrayassign.

gcc/d/ChangeLog:

	* expr.cc (ExprVisitor::visit (AssignExp *)): Clarify comment
	  for generating static array assignment with literal.
---
 gcc/d/expr.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 85269c6b2be..76c1e613e77 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1163,9 +1163,9 @@ public:
 	bool destructor = needs_dtor (etype);
 	bool lvalue = lvalue_p (e->e2);
 
-	/* Even if the elements in rhs are all rvalues and don't have
-	   to call postblits, this assignment should call dtors on old
-	   assigned elements.  */
+	/* Optimize static array assignment with array literal.  Even if the
+	   elements in rhs are all rvalues and don't have to call postblits,
+	   this assignment should call dtors on old assigned elements.  */
 	if ((!postblit && !destructor)
 	    || (e->op == TOKconstruct && e->e2->op == TOKarrayliteral)
 	    || (e->op == TOKconstruct && !lvalue && postblit)
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (7 preceding siblings ...)
  2021-07-30 11:01 ` [committed 09/12] d: Clarify comment for generating static array assignment with literal Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class Iain Buclaw
  2021-07-30 11:01 ` [committed 12/12] d: Remove dead code from binary_op Iain Buclaw
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

This expression is just discarded by add_stmt, so never reaches the
middle-end.

gcc/d/ChangeLog:

	* expr.cc (ExprVisitor::visit (AssertExp *)): Don't generate
	PREDICT_EXPR.
---
 gcc/d/expr.cc | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 76c1e613e77..73e0abeaa43 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2085,15 +2085,9 @@ public:
       }
     else
       {
-	/* Assert contracts are turned off, if the contract condition has no
-	   side effects can still use it as a predicate for the optimizer.  */
-	if (TREE_SIDE_EFFECTS (arg))
-	  {
-	    this->result_ = void_node;
-	    return;
-	  }
-
-	assert_fail = build_predict_expr (PRED_NORETURN, NOT_TAKEN);
+	/* Assert contracts are turned off.  */
+	this->result_ = void_node;
+	return;
       }
 
     /* Build condition that we are asserting in this contract.  */
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (8 preceding siblings ...)
  2021-07-30 11:01 ` [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  2021-07-30 11:01 ` [committed 12/12] d: Remove dead code from binary_op Iain Buclaw
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

Makes it explicit that the default value is set to NULL.

gcc/d/ChangeLog:

	* typeinfo.cc (TypeInfoVisitor::visit (TypeInfoClassDeclaration *)):
	Always layout initializer for the m_RTInfo field.
---
 gcc/d/typeinfo.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index c9126f4c6b5..978c73e65f6 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -934,6 +934,8 @@ public:
 	  this->layout_field (build_expr (cd->getRTInfo, true));
 	else if (!(flags & ClassFlags::noPointers))
 	  this->layout_field (size_one_node);
+	else
+	  this->layout_field (null_pointer_node);
       }
     else
       {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [committed 12/12] d: Remove dead code from binary_op.
  2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
                   ` (9 preceding siblings ...)
  2021-07-30 11:01 ` [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class Iain Buclaw
@ 2021-07-30 11:01 ` Iain Buclaw
  10 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

The front-end ensures that both sides have been casted to the same type
before being given to the lowering pass.

gcc/d/ChangeLog:

	* expr.cc (binary_op): Remove dead code.
---
 gcc/d/expr.cc | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 73e0abeaa43..e293cf2a4cd 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -101,8 +101,6 @@ binary_op (tree_code code, tree type, tree arg0, tree arg1)
   tree t1 = TREE_TYPE (arg1);
   tree ret = NULL_TREE;
 
-  bool unsignedp = TYPE_UNSIGNED (t0) || TYPE_UNSIGNED (t1);
-
   /* Deal with float mod expressions immediately.  */
   if (code == FLOAT_MOD_EXPR)
     return build_float_modulus (type, arg0, arg1);
@@ -130,12 +128,6 @@ binary_op (tree_code code, tree type, tree arg0, tree arg1)
       else
 	ret = fold_build2 (POINTER_DIFF_EXPR, ptrtype, arg0, arg1);
     }
-  else if (INTEGRAL_TYPE_P (type) && (TYPE_UNSIGNED (type) != unsignedp))
-    {
-      tree inttype = (unsignedp)
-	? d_unsigned_type (type) : d_signed_type (type);
-      ret = fold_build2 (code, inttype, arg0, arg1);
-    }
   else
     {
       /* If the operation needs excess precision.  */
-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [committed 03/12] d: Insert null terminator in obstack buffers
  2021-07-30 11:01 ` [committed 03/12] d: Insert null terminator in obstack buffers Iain Buclaw
@ 2021-11-25 14:09   ` Martin Liška
  2021-11-26 12:35     ` Iain Buclaw
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2021-11-25 14:09 UTC (permalink / raw)
  To: Iain Buclaw, gcc-patches

On 7/30/21 13:01, Iain Buclaw via Gcc-patches wrote:
> |Covers cases where functions that handle the extracted strings ignore the explicit length. This isn't something that's known to happen in the current front-end, but the self-hosted front-end has been observed to do this in its conversions between D and C-style strings.|

Can you please cherry pick this for gcc-11 branch as I see nasty output when using --verbose:

$ gcc /home/marxin/Programming/gcc/gcc/testsuite/gdc.dg/attr_optimize4.d -c --verbose
...
predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm D_LP64 assert D_ModuleInfo D_Exceptions D_TypeInfo all X86_64 D_HardFloat Posix linux CRuntime_Glibc CppRuntime_Gcc����������������������...


Thanks,
Martin

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [committed 03/12] d: Insert null terminator in obstack buffers
  2021-11-25 14:09   ` Martin Liška
@ 2021-11-26 12:35     ` Iain Buclaw
  2021-11-29  0:31       ` Iain Buclaw
  0 siblings, 1 reply; 15+ messages in thread
From: Iain Buclaw @ 2021-11-26 12:35 UTC (permalink / raw)
  To: gcc-patches, Martin Liška

Excerpts from Martin Liška's message of November 25, 2021 3:09 pm:
> On 7/30/21 13:01, Iain Buclaw via Gcc-patches wrote:
>> |Covers cases where functions that handle the extracted strings ignore the explicit length. This isn't something that's known to happen in the current front-end, but the self-hosted front-end has been observed to do this in its conversions between D and C-style strings.|
> 
> Can you please cherry pick this for gcc-11 branch as I see nasty output when using --verbose:
> 
> $ gcc /home/marxin/Programming/gcc/gcc/testsuite/gdc.dg/attr_optimize4.d -c --verbose
> ...
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm D_LP64 assert D_ModuleInfo D_Exceptions D_TypeInfo all X86_64 D_HardFloat Posix linux CRuntime_Glibc CppRuntime_Gcc����������������������...
> 
> 

Ouch, I'll have a look at gcc-9 and 10 too to see if they are the same.

Iain.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [committed 03/12] d: Insert null terminator in obstack buffers
  2021-11-26 12:35     ` Iain Buclaw
@ 2021-11-29  0:31       ` Iain Buclaw
  0 siblings, 0 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-11-29  0:31 UTC (permalink / raw)
  To: gcc-patches, Martin Liška

Excerpts from Iain Buclaw's message of November 26, 2021 1:35 pm:
> Excerpts from Martin Liška's message of November 25, 2021 3:09 pm:
>> On 7/30/21 13:01, Iain Buclaw via Gcc-patches wrote:
>>> |Covers cases where functions that handle the extracted strings ignore the explicit length. This isn't something that's known to happen in the current front-end, but the self-hosted front-end has been observed to do this in its conversions between D and C-style strings.|
>> 
>> Can you please cherry pick this for gcc-11 branch as I see nasty output when using --verbose:
>> 
>> $ gcc /home/marxin/Programming/gcc/gcc/testsuite/gdc.dg/attr_optimize4.d -c --verbose
>> ...
>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm D_LP64 assert D_ModuleInfo D_Exceptions D_TypeInfo all X86_64 D_HardFloat Posix linux CRuntime_Glibc CppRuntime_Gcc����������������������...
>> 
>> 
> 
> Ouch, I'll have a look at gcc-9 and 10 too to see if they are the same.
> 

FYI, patch applied cleanly to gcc-11 branch and has been committed.
Saw no regressions on x86_64-linux-gnu in both bootstrap and tests.

Checked other branches, however earlier releases used the dmd
front-end's OutBuffer, so are unaffected.

Iain.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-11-29  0:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
2021-07-30 11:01 ` [committed 03/12] d: Insert null terminator in obstack buffers Iain Buclaw
2021-11-25 14:09   ` Martin Liška
2021-11-26 12:35     ` Iain Buclaw
2021-11-29  0:31       ` Iain Buclaw
2021-07-30 11:01 ` [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw
2021-07-30 11:01 ` [committed 05/12] d: Use Identifier::idPool to generate anonymous field name Iain Buclaw
2021-07-30 11:01 ` [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations Iain Buclaw
2021-07-30 11:01 ` [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public Iain Buclaw
2021-07-30 11:01 ` [committed 08/12] d: Only handle named enums in enum_initializer_decl Iain Buclaw
2021-07-30 11:01 ` [committed 09/12] d: Clarify comment for generating static array assignment with literal Iain Buclaw
2021-07-30 11:01 ` [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off Iain Buclaw
2021-07-30 11:01 ` [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class Iain Buclaw
2021-07-30 11:01 ` [committed 12/12] d: Remove dead code from binary_op 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).