public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] d: Consistently format quotations in comments.
@ 2020-06-16 21:59 Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Move generation of array bounds error to own function Iain Buclaw
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch updates comments to consistently format quotations in code
comments throughout the D front-end.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-builtins.cc: Update quotation formatting of comments.
	* d-codegen.cc: Likewise.
	* d-lang.cc: Likewise.
	* decl.cc: Likewise.
	* expr.cc: Likewise.
	* imports.cc: Likewise.
	* runtime.cc: Likewise.
	* toir.cc: Likewise.
	* typeinfo.cc: Likewise.
	* types.cc: Likewise.
---
 gcc/d/d-builtins.cc |  2 +-
 gcc/d/d-codegen.cc  | 28 ++++++++++++++--------------
 gcc/d/d-lang.cc     |  2 +-
 gcc/d/decl.cc       | 22 +++++++++++-----------
 gcc/d/expr.cc       |  8 ++++----
 gcc/d/imports.cc    |  2 +-
 gcc/d/runtime.cc    |  2 +-
 gcc/d/toir.cc       | 22 +++++++++++-----------
 gcc/d/typeinfo.cc   |  4 ++--
 gcc/d/types.cc      |  4 ++--
 10 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index f1bdcb9fafd..75eaa6b8a73 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -222,7 +222,7 @@ build_frontend_type (tree type)
 	Identifier::idPool (IDENTIFIER_POINTER (TYPE_IDENTIFIER (type))) : NULL;
 
       /* Neither the `object' and `gcc.builtins' modules will not exist when
-	 this is called.  Use a stub 'object' module parent in the meantime.
+	 this is called.  Use a stub `object' module parent in the meantime.
 	 If `gcc.builtins' is later imported, the parent will be overridden
 	 with the correct module symbol.  */
       static Identifier *object = Identifier::idPool ("object");
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 9d13e1263a9..b82e16fe79e 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -82,7 +82,7 @@ d_decl_context (Dsymbol *dsym)
 	  return build_import_decl (parent);
 	}
 
-      /* Declarations marked as 'static' or '__gshared' are never
+      /* Declarations marked as `static' or `__gshared' are never
 	 part of any context except at module level.  */
       if (decl != NULL && decl->isDataseg ())
 	continue;
@@ -164,7 +164,7 @@ declaration_type (Declaration *decl)
   if (declaration_reference_p (decl))
     return build_reference_type (type);
 
-  /* The 'this' parameter is always const.  */
+  /* The `this' parameter is always const.  */
   if (decl->isThisDeclaration ())
     return insert_type_modifiers (type, MODconst);
 
@@ -1830,7 +1830,7 @@ call_by_alias_p (FuncDeclaration *caller, FuncDeclaration *callee)
 }
 
 /* Entry point for call routines.  Builds a function call to FD.
-   OBJECT is the 'this' reference passed and ARGS are the arguments to FD.  */
+   OBJECT is the `this' reference passed and ARGS are the arguments to FD.  */
 
 tree
 d_build_call_expr (FuncDeclaration *fd, tree object, Expressions *arguments)
@@ -1839,7 +1839,7 @@ d_build_call_expr (FuncDeclaration *fd, tree object, Expressions *arguments)
 		       build_address (get_symbol_decl (fd)), object, arguments);
 }
 
-/* Builds a CALL_EXPR of type TF to CALLABLE.  OBJECT holds the 'this' pointer,
+/* Builds a CALL_EXPR of type TF to CALLABLE.  OBJECT holds the `this' pointer,
    ARGUMENTS are evaluated in left to right order, saved and promoted
    before passing.  */
 
@@ -2044,7 +2044,7 @@ build_float_modulus (tree type, tree arg0, tree arg1)
 }
 
 /* Build a function type whose first argument is a pointer to BASETYPE,
-   which is to be used for the 'vthis' context parameter for TYPE.
+   which is to be used for the `vthis' context parameter for TYPE.
    The base type may be a record for member functions, or a void for
    nested functions and delegates.  */
 
@@ -2085,7 +2085,7 @@ get_frame_for_symbol (Dsymbol *sym)
       /* Check that the nested function is properly defined.  */
       if (!fd->fbody)
 	{
-	  /* Should instead error on line that references 'fd'.  */
+	  /* Should instead error on line that references `fd'.  */
 	  error_at (make_location_t (fd->loc), "nested function missing body");
 	  return null_pointer_node;
 	}
@@ -2181,7 +2181,7 @@ get_frame_for_symbol (Dsymbol *sym)
     {
       tree frame_ref = get_framedecl (thisfd, fdparent);
 
-      /* If 'thisfd' is a derived member function, then 'fdparent' is the
+      /* If `thisfd' is a derived member function, then `fdparent' is the
 	 overridden member function in the base class.  Even if there's a
 	 closure environment, we should give the original stack data as the
 	 nested function frame.  */
@@ -2195,12 +2195,12 @@ get_frame_for_symbol (Dsymbol *sym)
 	  if (cdo->isBaseOf (cd, &offset) && offset != 0)
 	    {
 	      /* Generate a new frame to pass to the overriden function that
-		 has the 'this' pointer adjusted.  */
+		 has the `this' pointer adjusted.  */
 	      gcc_assert (offset != OFFSET_RUNTIME);
 
 	      tree type = FRAMEINFO_TYPE (get_frameinfo (fdoverride));
 	      tree fields = TYPE_FIELDS (type);
-	      /* The 'this' field comes immediately after the '__chain'.  */
+	      /* The `this' field comes immediately after the `__chain'.  */
 	      tree thisfield = chain_index (1, fields);
 	      vec<constructor_elt, va_gc> *ve = NULL;
 
@@ -2263,7 +2263,7 @@ d_nested_struct (StructDeclaration *sd)
 
 
 /* Starting from the current function FD, try to find a suitable value of
-   'this' in nested function instances.  A suitable 'this' value is an
+   `this' in nested function instances.  A suitable `this' value is an
    instance of OCD or a class that has OCD as a base.  */
 
 static tree
@@ -2301,7 +2301,7 @@ find_this_tree (ClassDeclaration *ocd)
   return NULL_TREE;
 }
 
-/* Retrieve the outer class/struct 'this' value of DECL from
+/* Retrieve the outer class/struct `this' value of DECL from
    the current function.  */
 
 tree
@@ -2327,7 +2327,7 @@ build_vthis (AggregateDeclaration *decl)
 	  outer = ((TemplateInstance *) outer->parent)->enclosing;
 	}
 
-      /* For outer classes, get a suitable 'this' value.
+      /* For outer classes, get a suitable `this' value.
 	 For outer functions, get a suitable frame/closure pointer.  */
       ClassDeclaration *cdo = outer->isClassDeclaration ();
       FuncDeclaration *fdo = outer->isFuncDeclaration ();
@@ -2412,7 +2412,7 @@ build_frame_type (tree ffi, FuncDeclaration *fd)
 	    }
 	}
 
-      /* Also add hidden 'this' to outer context.  */
+      /* Also add hidden `this' to outer context.  */
       if (fd->vthis)
 	{
 	  for (size_t i = 0; i < fd->closureVars.length; i++)
@@ -2542,7 +2542,7 @@ build_closure (FuncDeclaration *fd)
 }
 
 /* Return the frame of FD.  This could be a static chain or a closure
-   passed via the hidden 'this' pointer.  */
+   passed via the hidden `this' pointer.  */
 
 tree
 get_frameinfo (FuncDeclaration *fd)
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 34fbc5f41d8..dd5a83cb4fe 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -337,7 +337,7 @@ d_init_options_struct (gcc_options *opts)
   /* Avoid range issues for complex multiply and divide.  */
   opts->x_flag_complex_method = 2;
 
-  /* Unlike C, there is no global 'errno' variable.  */
+  /* Unlike C, there is no global `errno' variable.  */
   opts->x_flag_errno_math = 0;
   opts->frontend_set_flag_errno_math = true;
 
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 28d1d6d5f31..f43b334aac7 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -859,7 +859,7 @@ public:
 
     /* Special arguments...  */
 
-    /* 'this' parameter:
+    /* `this' parameter:
        For nested functions, D still generates a vthis, but it
        should not be referenced in any expression.  */
     if (d->vthis)
@@ -1205,7 +1205,7 @@ get_symbol_decl (Declaration *decl)
 	}
       else if (fd->isThis ())
 	{
-	  /* Add an extra argument for the 'this' parameter.  The handle type is
+	  /* Add an extra argument for the `this' parameter.  The handle type is
 	     used even if there is no debug info.  It is needed to make sure
 	     virtual member functions are not called statically.  */
 	  AggregateDeclaration *ad = fd->isMember2 ();
@@ -1226,11 +1226,11 @@ get_symbol_decl (Declaration *decl)
 	}
       else if (fd->isMain () || fd->isCMain ())
 	{
-	  /* The main function is named 'D main' to distinguish from C main.  */
+	  /* The main function is named `D main' to distinguish from C main.  */
 	  if (fd->isMain ())
 	    DECL_NAME (decl->csym) = get_identifier (fd->toPrettyChars (true));
 
-	  /* 'void main' is implicitly converted to returning an int.  */
+	  /* `void main' is implicitly converted to returning an int.  */
 	  newfntype = build_function_type (d_int_type, TYPE_ARG_TYPES (fntype));
 	}
 
@@ -1253,14 +1253,14 @@ get_symbol_decl (Declaration *decl)
 	  DECL_NO_INLINE_WARNING_P (decl->csym) = 1;
 	}
 
-      /* In [pragma/inline], functions decorated with 'pragma(inline)' affects
+      /* In [pragma/inline], functions decorated with `pragma(inline)' affects
 	 whether they are inlined or not.  */
       if (fd->inlining == PINLINEalways)
 	DECL_DECLARED_INLINE_P (decl->csym) = 1;
       else if (fd->inlining == PINLINEnever)
 	DECL_UNINLINABLE (decl->csym) = 1;
 
-      /* Function was declared 'naked'.  */
+      /* Function was declared `naked'.  */
       if (fd->naked)
 	{
 	  insert_decl_attribute (decl->csym, "naked");
@@ -1466,7 +1466,7 @@ get_decl_tree (Declaration *decl)
 			    DECL_LANG_FRAME_FIELD (t));
     }
 
-  /* Get the non-local 'this' value by going through parent link
+  /* Get the non-local `this' value by going through parent link
      of nested classes, this routine pretty much undoes what
      getRightThis in the frontend removes from codegen.  */
   if (vd->parent != fd && vd->isThisDeclaration ())
@@ -1501,9 +1501,9 @@ get_decl_tree (Declaration *decl)
 	  fd = outer->isFuncDeclaration ();
 	  while (fd != NULL)
 	    {
-	      /* If outer function creates a closure, then the 'this'
+	      /* If outer function creates a closure, then the `this'
 		 value would be the closure pointer, and the real
-		 'this' the first field of that closure.  */
+		 `this' the first field of that closure.  */
 	      tree ff = get_frameinfo (fd);
 	      if (FRAMEINFO_CREATES_FRAME (ff))
 		{
@@ -1900,7 +1900,7 @@ start_function (FuncDeclaration *fd)
   cfun->language = ggc_cleared_alloc<language_function> ();
   cfun->language->function = fd;
 
-  /* Default chain value is 'null' unless parent found.  */
+  /* Default chain value is `null' unless parent found.  */
   cfun->language->static_chain = null_pointer_node;
 
   /* Find module for this function.  */
@@ -2194,7 +2194,7 @@ build_new_class_expr (ClassReferenceExp *expr)
 
 /* Get the VAR_DECL of the static initializer symbol for the struct/class DECL.
    If this does not yet exist, create it.  The static initializer data is
-   accessible via TypeInfo, and is also used in 'new class' and default
+   accessible via TypeInfo, and is also used in `new class' and default
    initializing struct literals.  */
 
 tree
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index bf9bb45690a..e1842cc6fee 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1739,7 +1739,7 @@ public:
 		    thisexp = TREE_OPERAND (thisexp, 1);
 		  }
 
-		/* Want reference to 'this' object.  */
+		/* Want reference to `this' object.  */
 		if (!POINTER_TYPE_P (TREE_TYPE (thisexp)))
 		  thisexp = build_address (thisexp);
 
@@ -1770,7 +1770,7 @@ public:
 	  {
 	    /* This gets the true function type, getting the function type
 	       from e1->type can sometimes be incorrect, such as when calling
-	       a 'ref' return function.  */
+	       a `ref' return function.  */
 	    tf = get_function_type (e1b->isDotVarExp ()->var->type);
 	  }
 	else
@@ -1794,7 +1794,7 @@ public:
 
 	if (fd->isNested ())
 	  {
-	    /* Maybe re-evaluate symbol storage treating 'fd' as public.  */
+	    /* Maybe re-evaluate symbol storage treating `fd' as public.  */
 	    if (call_by_alias_p (d_function_chain->function, fd))
 	      TREE_PUBLIC (callee) = 1;
 
@@ -2099,7 +2099,7 @@ public:
   {
     Type *ftype = e->type->toBasetype ();
 
-    /* This check is for lambda's, remove 'vthis' as function isn't nested.  */
+    /* This check is for lambda's, remove `vthis' as function isn't nested.  */
     if (e->fd->tok == TOKreserved && ftype->ty == Tpointer)
       {
 	e->fd->tok = TOKfunction;
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index e6e696ab325..34cd5e1fdd2 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -202,7 +202,7 @@ build_import_decl (Dsymbol *d)
       input_location = saved_location;
     }
 
-  /* Not all visitors set 'isym'.  */
+  /* Not all visitors set `isym'.  */
   return d->isym ? d->isym : NULL_TREE;
 }
 
diff --git a/gcc/d/runtime.cc b/gcc/d/runtime.cc
index ab1c04db4de..b4426e150ba 100644
--- a/gcc/d/runtime.cc
+++ b/gcc/d/runtime.cc
@@ -219,7 +219,7 @@ build_libcall_decl (const char *name, d_libcall_type return_type,
   bool varargs = false;
   tree fntype;
 
-  /* Add parameter types, using 'void' as the last parameter type
+  /* Add parameter types, using `void' as the last parameter type
      to mean this function accepts a variable list of arguments.  */
   va_list ap;
   va_start (ap, nparams);
diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc
index 130cbbafe00..b6f72092e5f 100644
--- a/gcc/d/toir.cc
+++ b/gcc/d/toir.cc
@@ -564,14 +564,14 @@ public:
   {
     this->start_scope (level_cond);
 
-    /* Build the outer 'if' condition, which may produce temporaries
+    /* Build the outer `if' condition, which may produce temporaries
        requiring scope destruction.  */
     tree ifcond = convert_for_condition (build_expr_dtor (s->condition),
 					 s->condition->type);
     tree ifbody = void_node;
     tree elsebody = void_node;
 
-    /* Build the 'then' branch.  */
+    /* Build the `then' branch.  */
     if (s->ifbody)
       {
 	push_stmt_list ();
@@ -579,7 +579,7 @@ public:
 	ifbody = pop_stmt_list ();
       }
 
-    /* Now build the 'else' branch, which may have nested 'else if' parts.  */
+    /* Now build the `else' branch, which may have nested `else if' parts.  */
     if (s->elsebody)
       {
 	push_stmt_list ();
@@ -627,7 +627,7 @@ public:
 	this->pop_continue_label (lcontinue);
       }
 
-    /* Build the outer 'while' condition, which may produce temporaries
+    /* Build the outer `while' condition, which may produce temporaries
        requiring scope destruction.  */
     tree exitcond = convert_for_condition (build_expr_dtor (s->condition),
 					   s->condition->type);
@@ -885,7 +885,7 @@ public:
 	  {
 	    tree defaultlabel = this->lookup_label (s->sdefault);
 
-	    /* The default label is the last 'else' block.  */
+	    /* The default label is the last `else' block.  */
 	    if (s->hasVars)
 	      {
 		this->do_jump (defaultlabel);
@@ -917,7 +917,7 @@ public:
 
     SWITCH_BREAK_LABEL_P (lbreak) = 1;
 
-    /* If the switch had any 'break' statements, emit the label now.  */
+    /* If the switch had any `break' statements, emit the label now.  */
     this->pop_break_label (lbreak);
     this->finish_scope ();
   }
@@ -968,7 +968,7 @@ public:
       this->build_stmt (s->statement);
   }
 
-  /* Implements 'goto default' by jumping to the label associated with
+  /* Implements `goto default' by jumping to the label associated with
      the DefaultStatement in a switch block.  */
 
   void visit (GotoDefaultStatement *s)
@@ -977,7 +977,7 @@ public:
     this->do_jump (label);
   }
 
-  /* Implements 'goto case' by jumping to the label associated with the
+  /* Implements `goto case' by jumping to the label associated with the
      CaseStatement in a switch block.  */
 
   void visit (GotoCaseStatement *s)
@@ -1112,7 +1112,7 @@ public:
 
     if (s->wthis)
       {
-	/* Perform initialisation of the 'with' handle.  */
+	/* Perform initialisation of the `with' handle.  */
 	ExpInitializer *ie = s->wthis->_init->isExpInitializer ();
 	gcc_assert (ie != NULL);
 
@@ -1127,7 +1127,7 @@ public:
     this->finish_scope ();
   }
 
-  /* Implements 'throw Object'.  Frontend already checks that the object
+  /* Implements `throw Object'.  Frontend already checks that the object
      thrown is a class type, but does not check if it is derived from
      Object.  Foreign objects are not currently supported at run-time.  */
 
@@ -1432,7 +1432,7 @@ public:
        optimization, this could be unset when building in release mode.  */
     ASM_VOLATILE_P (exp) = 1;
 
-    /* If the function has been annotated with 'pragma(inline)', then mark
+    /* If the function has been annotated with `pragma(inline)', then mark
        the asm expression as being inline as well.  */
     if (this->func_->inlining == PINLINEalways)
       ASM_INLINE_P (exp) = 1;
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index f3051d3e122..b03019bdff5 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -456,7 +456,7 @@ class TypeInfoVisitor : public Visitor
 	    CONSTRUCTOR_APPEND_ELT (v, size_int (2), value);
 	  }
 
-	/* The 'this' offset.  */
+	/* The `this' offset.  */
 	CONSTRUCTOR_APPEND_ELT (v, size_int (3), size_int (b->offset));
 
 	/* Add to the array of interfaces.  */
@@ -1483,7 +1483,7 @@ create_typeinfo (Type *type, Module *mod)
 	  /* Kinds of TypeInfo that add one extra pointer field.  */
 	  if (tk == TK_SHARED_TYPE)
 	    {
-	      /* Does both 'shared' and 'shared const'.  */
+	      /* Does both `shared' and `shared const'.  */
 	      t->vtinfo = TypeInfoSharedDeclaration::create (t);
 	      ident = Identifier::idPool ("TypeInfo_Shared");
 	    }
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index ba7e29a12e1..b8984a50ff0 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -106,7 +106,7 @@ same_type_p (Type *t1, Type *t2)
   return false;
 }
 
-/* Returns 'Object' type which all D classes are derived from.  */
+/* Returns `Object' type which all D classes are derived from.  */
 
 Type *
 get_object_type (void)
@@ -204,7 +204,7 @@ insert_type_modifiers (tree type, unsigned mod)
 
   tree qualtype = build_qualified_type (type, quals);
 
-  /* Mark whether the type is qualified 'shared'.  */
+  /* Mark whether the type is qualified `shared'.  */
   if (mod & MODshared)
     TYPE_SHARED (qualtype) = 1;
 
-- 
2.25.1


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

* [committed] d: Move generation of array bounds error to own function.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Remove dependency on front-end File type for json and deps file generation Iain Buclaw
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch moves a couple code duplications into its own routine, the
checkAction global parameter is now initialized and properly adjusted.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-codegen.cc (build_array_bounds_call): New function.
	(build_bounds_condition): Use build_array_bounds_call.
	* d-lang.cc (d_init_options): Explicitly set default check action to
	CHECKACTION_D.
	(d_post_options): Set check action to CHECKACTION_C if the flag
	-fno-druntime was seen.
	* d-tree.h (build_array_bounds_call): Declare.
	* expr.cc (ExprVisitor::visit (AssertExp *)): Use
	build_array_bounds_call.
---
 gcc/d/d-codegen.cc | 24 +++++++++++++++++++++---
 gcc/d/d-lang.cc    |  3 ++-
 gcc/d/d-tree.h     |  1 +
 gcc/d/expr.cc      |  4 +---
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index d31638e2c1d..9d13e1263a9 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1712,6 +1712,26 @@ void_okay_p (tree t)
   return t;
 }
 
+/* Builds a CALL_EXPR at location LOC in the source file to execute when an
+   array bounds check fails.  */
+
+tree
+build_array_bounds_call (const Loc &loc)
+{
+  switch (global.params.checkAction)
+    {
+    case CHECKACTION_D:
+      return d_assert_call (loc, LIBCALL_ARRAY_BOUNDS);
+
+    case CHECKACTION_C:
+    case CHECKACTION_halt:
+      return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);
+
+    default:
+      gcc_unreachable ();
+    }
+}
+
 /* Builds a bounds condition checking that INDEX is between 0 and LEN.
    The condition returns the INDEX if true, or throws a RangeError.
    If INCLUSIVE, we allow INDEX == LEN to return true also.  */
@@ -1731,9 +1751,7 @@ build_bounds_condition (const Loc& loc, tree index, tree len, bool inclusive)
   tree condition = fold_build2 (inclusive ? GT_EXPR : GE_EXPR,
 				d_bool_type, index, len);
   /* Terminate the program with a trap if no D runtime present.  */
-  tree boundserr = (global.params.checkAction == CHECKACTION_D)
-    ? d_assert_call (loc, LIBCALL_ARRAY_BOUNDS)
-    : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);
+  tree boundserr = build_array_bounds_call (loc);
 
   return build_condition (TREE_TYPE (index), condition, boundserr, index);
 }
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 5266a6550dc..085d8393b5a 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -285,6 +285,7 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options)
   global.params.useOut = CHECKENABLEdefault;
   global.params.useArrayBounds = CHECKENABLEdefault;
   global.params.useSwitchError = CHECKENABLEdefault;
+  global.params.checkAction = CHECKACTION_D;
   global.params.useModuleInfo = true;
   global.params.useTypeInfo = true;
   global.params.useExceptions = true;
@@ -775,7 +776,7 @@ d_post_options (const char ** fn)
       if (!global_options_set.x_flag_exceptions)
 	global.params.useExceptions = false;
 
-      global.params.checkAction = CHECKACTION_halt;
+      global.params.checkAction = CHECKACTION_C;
     }
 
   /* Keep in sync with existing -fbounds-check flag.  */
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 3338e88b278..dd38b732837 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -560,6 +560,7 @@ extern tree build_memref (tree, tree, tree);
 extern tree build_array_set (tree, tree, tree);
 extern tree build_array_from_val (Type *, tree);
 extern tree void_okay_p (tree);
+extern tree build_array_bounds_call (const Loc &);
 extern tree build_bounds_condition (const Loc &, tree, tree, bool);
 extern bool array_bounds_check (void);
 extern tree bind_expr (tree, tree);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 06cd83a737d..bf9bb45690a 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1218,9 +1218,7 @@ public:
 
 	if (!e->indexIsInBounds && array_bounds_check ())
 	  {
-	    tree tassert = (global.params.checkAction == CHECKACTION_D)
-	      ? d_assert_call (e->loc, LIBCALL_ARRAY_BOUNDS)
-	      : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0);
+	    tree tassert = build_array_bounds_call (e->loc);
 
 	    result = d_save_expr (result);
 	    result = build_condition (TREE_TYPE (result),
-- 
2.25.1


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

* [committed] d: Remove dependency on front-end File type for json and deps file generation.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Move generation of array bounds error to own function Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Remove dependency on front-end OutBuffer for diagnostic " Iain Buclaw
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces some uses of File with FILE.  Memory allocated by
the DMD front-end is never freed due to the bump pointer allocator used
internally.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-lang.cc (d_parse_file): Replace uses of File with FILE.
---
 gcc/d/d-lang.cc | 42 ++++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 085d8393b5a..fe59abe93a8 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1271,6 +1271,7 @@ d_parse_file (void)
   if (d_option.deps)
     {
       OutBuffer buf;
+      FILE *deps_stream;
 
       for (size_t i = 0; i < modules.length; i++)
 	deps_write (modules[i], &buf);
@@ -1281,13 +1282,25 @@ d_parse_file (void)
 
       if (d_option.deps_filename)
 	{
-	  File *fdeps = File::create (d_option.deps_filename);
-	  fdeps->setbuffer ((void *) buf.data, buf.offset);
-	  fdeps->ref = 1;
-	  writeFile (Loc (), fdeps);
+	  deps_stream = fopen (d_option.deps_filename, "w");
+	  if (!deps_stream)
+	    {
+	      fatal_error (input_location, "opening dependency file %s: %m",
+			   d_option.deps_filename);
+	      goto had_errors;
+	    }
 	}
       else
-	message ("%.*s", (int) buf.offset, (char *) buf.data);
+	deps_stream = stdout;
+
+      fprintf (deps_stream, "%s", buf.peekChars ());
+
+      if (deps_stream != stdout
+	  && (ferror (deps_stream) || fclose (deps_stream)))
+	{
+	  fatal_error (input_location, "closing dependency file %s: %m",
+		       d_option.deps_filename);
+	}
     }
 
   /* Generate JSON files.  */
@@ -1297,18 +1310,27 @@ d_parse_file (void)
       json_generate (&buf, &modules);
 
       const char *name = global.params.jsonfilename.ptr;
+      FILE *json_stream;
 
       if (name && (name[0] != '-' || name[1] != '\0'))
 	{
 	  const char *nameext
 	    = FileName::defaultExt (name, global.json_ext.ptr);
-	  File *fjson = File::create (nameext);
-	  fjson->setbuffer ((void *) buf.data, buf.offset);
-	  fjson->ref = 1;
-	  writeFile (Loc (), fjson);
+	  json_stream = fopen (nameext, "w");
+	  if (!json_stream)
+	    {
+	      fatal_error (input_location, "opening json file %s: %m", nameext);
+	      goto had_errors;
+	    }
 	}
       else
-	message ("%.*s", (int) buf.offset, (char *) buf.data);
+	json_stream = stdout;
+
+      fprintf (json_stream, "%s", buf.peekChars ());
+
+      if (json_stream != stdout
+	  && (ferror (json_stream) || fclose (json_stream)))
+	fatal_error (input_location, "closing json file %s: %m", name);
     }
 
   /* Generate Ddoc files.  */
-- 
2.25.1


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

* [committed] d: Remove dependency on front-end OutBuffer for diagnostic and deps file generation.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Move generation of array bounds error to own function Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Remove dependency on front-end File type for json and deps file generation Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Remove names of unused function parameters Iain Buclaw
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces some uses of OutBuffer with obstack.  Memory
allocated by the DMD front-end is never freed due to the
bump pointer allocator used internally.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-diagnostic.cc (expand_d_format): Replace OutBuffer with obstack.
	(d_diagnostic_report_diagnostic): Don't free xformat.
	* d-lang.cc (struct d_option_data): Change deps_target type from
	OutBuffer to vec <const char *>.
	(deps_add_target): Update to push each target to deps_target.
	(deps_write_string): New function.
	(deps_write): Change buffer type to obstack* and remove colmax.
	(d_init_options): Update initialization of deps_target.
	(d_parse_file): Replace OutBuffer with obstack.
---
 gcc/d/d-diagnostic.cc |  22 ++++-----
 gcc/d/d-lang.cc       | 106 +++++++++++++++++++++++-------------------
 2 files changed, 68 insertions(+), 60 deletions(-)

diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index bf10b11d600..ee5f6e23df2 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -36,21 +36,21 @@ along with GCC; see the file COPYING3.  If not see
    `...`: text within backticks gets quoted as '%<...%>'.
    %-10s: left-justify format flag is removed leaving '%s' remaining.
    %02x: zero-padding format flag is removed leaving '%x' remaining.
-   %X: uppercase unsigned hexadecimals are rewritten as '%x'.
-
-   The result should be freed by the caller.  */
+   %X: uppercase unsigned hexadecimals are rewritten as '%x'.  */
 
 static char *
 expand_d_format (const char *format)
 {
-  OutBuffer buf;
+  obstack buf;
   bool inbacktick = false;
 
+  gcc_obstack_init (&buf);
+
   for (const char *p = format; *p;)
     {
       while (*p != '\0' && *p != '%' && *p != '`')
 	{
-	  buf.writeByte (*p);
+	  obstack_1grow (&buf, *p);
 	  p++;
 	}
 
@@ -62,12 +62,12 @@ expand_d_format (const char *format)
 	  /* Text enclosed by `...` are translated as a quoted string.  */
 	  if (inbacktick)
 	    {
-	      buf.writestring ("%>");
+	      obstack_grow (&buf, "%>", 2);
 	      inbacktick = false;
 	    }
 	  else
 	    {
-	      buf.writestring ("%<");
+	      obstack_grow (&buf, "%<", 2);
 	      inbacktick = true;
 	    }
 	  p++;
@@ -75,7 +75,7 @@ expand_d_format (const char *format)
 	}
 
       /* Check the conversion specification for unhandled flags.  */
-      buf.writeByte (*p);
+      obstack_1grow (&buf, *p);
       p++;
 
     Lagain:
@@ -100,7 +100,7 @@ expand_d_format (const char *format)
 
 	case 'X':
 	  /* Hex format only supports lower-case.  */
-	  buf.writeByte ('x');
+	  obstack_1grow (&buf, 'x');
 	  p++;
 	  break;
 
@@ -110,7 +110,8 @@ expand_d_format (const char *format)
     }
 
   gcc_assert (!inbacktick);
-  return buf.extractChars ();
+  obstack_1grow (&buf, '\0');
+  return (char *) obstack_finish (&buf);
 }
 
 /* Helper routine for all error routines.  Reports a diagnostic specified by
@@ -136,7 +137,6 @@ d_diagnostic_report_diagnostic (const Loc& loc, int opt, const char *format,
 	diagnostic.option_index = opt;
 
       diagnostic_report_diagnostic (global_dc, &diagnostic);
-      free (xformat);
     }
   else
     {
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index fe59abe93a8..34fbc5f41d8 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -73,7 +73,7 @@ struct d_option_data
   bool deps_skip_system;	    /* -MM  */
   const char *deps_filename;	    /* -M[M]D  */
   const char *deps_filename_user;   /* -MF <arg>  */
-  OutBuffer *deps_target;	    /* -M[QT] <arg> */
+  vec <const char *> deps_target;   /* -M[QT] <arg> */
   bool deps_phony;		    /* -MP  */
 
   bool stdinc;			    /* -nostdinc  */
@@ -104,16 +104,13 @@ static GTY(()) vec<tree, va_gc> *global_declarations;
 static void
 deps_add_target (const char *target, bool quoted)
 {
-  if (!d_option.deps_target)
-    d_option.deps_target = new OutBuffer ();
-  else
-    d_option.deps_target->writeByte (' ');
-
-  d_option.deps_target->reserve (strlen (target));
+  obstack buffer;
+  gcc_obstack_init (&buffer);
 
   if (!quoted)
     {
-      d_option.deps_target->writestring (target);
+      obstack_grow (&buffer, target, strlen (target));
+      d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
       return;
     }
 
@@ -125,31 +122,59 @@ deps_add_target (const char *target, bool quoted)
 	case ' ':
 	case '\t':
 	  for (const char *q = p - 1; target <= q && *q == '\\';  q--)
-	    d_option.deps_target->writeByte ('\\');
-	  d_option.deps_target->writeByte ('\\');
+	    obstack_1grow (&buffer, '\\');
+	  obstack_1grow (&buffer, '\\');
 	  break;
 
 	case '$':
-	  d_option.deps_target->writeByte ('$');
+	  obstack_1grow (&buffer, '$');
 	  break;
 
 	case '#':
-	  d_option.deps_target->writeByte ('\\');
+	  obstack_1grow (&buffer, '\\');
 	  break;
 
 	default:
 	  break;
 	}
 
-      d_option.deps_target->writeByte (*p);
+      obstack_1grow (&buffer, *p);
     }
+
+  d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
 }
 
-/* Write out all dependencies of a given MODULE to the specified BUFFER.
+/* Write STR, with a leading space to BUFFER, updating COLUMN as appropriate.
    COLMAX is the number of columns to word-wrap at (0 means don't wrap).  */
 
 static void
-deps_write (Module *module, OutBuffer *buffer, unsigned colmax = 72)
+deps_write_string (const char *str, obstack *buffer, unsigned &column,
+		   unsigned colmax = 72)
+{
+  unsigned size = strlen (str);
+
+  if (column != 0)
+    {
+      if (colmax && column + size > colmax)
+	{
+	  obstack_grow (buffer, " \\\n ", 4);
+	  column = 1;
+	}
+      else
+	{
+	  obstack_1grow (buffer, ' ');
+	  column++;
+	}
+    }
+
+  column += size;
+  obstack_grow (buffer, str, size);
+}
+
+/* Write out all dependencies of a given MODULE to the specified BUFFER.  */
+
+static void
+deps_write (Module *module, obstack *buffer)
 {
   hash_set <const char *> seen_modules;
   vec <const char *> dependencies = vNULL;
@@ -161,18 +186,15 @@ deps_write (Module *module, OutBuffer *buffer, unsigned colmax = 72)
   unsigned column = 0;
 
   /* Write out make target module name.  */
-  if (d_option.deps_target)
+  if (d_option.deps_target.length ())
     {
-      buffer->writestring (d_option.deps_target->extractChars ());
-      column = d_option.deps_target->offset;
+      for (unsigned i = 0; i < d_option.deps_target.length (); i++)
+	deps_write_string (d_option.deps_target[i], buffer, column);
     }
   else
-    {
-      buffer->writestring (module->objfile->name->str);
-      column = buffer->offset;
-    }
+    deps_write_string (module->objfile->name->str, buffer, column);
 
-  buffer->writestring (":");
+  obstack_1grow (buffer, ':');
   column++;
 
   /* Search all modules for file dependencies.  */
@@ -236,33 +258,17 @@ deps_write (Module *module, OutBuffer *buffer, unsigned colmax = 72)
 
   /* Write out all make dependencies.  */
   for (size_t i = 0; i < dependencies.length (); i++)
-    {
-      const char *str = dependencies[i];
-      unsigned size = strlen (str);
-      column += size;
-
-      if (colmax && column > colmax)
-	{
-	  buffer->writestring (" \\\n ");
-	  column = size + 1;
-	}
-      else
-	{
-	  buffer->writestring (" ");
-	  column++;
-	}
+    deps_write_string (dependencies[i], buffer, column);
 
-      buffer->writestring (str);
-    }
-
-  buffer->writenl ();
+  obstack_1grow (buffer, '\n');
 
   /* Write out all phony targets.  */
   for (size_t i = 0; i < phonylist.length (); i++)
     {
-      buffer->writenl ();
-      buffer->writestring (phonylist[i]);
-      buffer->writestring (":\n");
+      const char *str = phonylist[i];
+      obstack_1grow (buffer, '\n');
+      obstack_grow (buffer, str, strlen (str));
+      obstack_grow (buffer, ":\n", 2);
     }
 }
 
@@ -314,7 +320,7 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options)
   d_option.deps_skip_system = false;
   d_option.deps_filename = NULL;
   d_option.deps_filename_user = NULL;
-  d_option.deps_target = NULL;
+  d_option.deps_target = vNULL;
   d_option.deps_phony = false;
   d_option.stdinc = true;
 }
@@ -1270,11 +1276,13 @@ d_parse_file (void)
   /* Make dependencies.  */
   if (d_option.deps)
     {
-      OutBuffer buf;
+      obstack buffer;
       FILE *deps_stream;
 
+      gcc_obstack_init (&buffer);
+
       for (size_t i = 0; i < modules.length; i++)
-	deps_write (modules[i], &buf);
+	deps_write (modules[i], &buffer);
 
       /* -MF <arg> overrides -M[M]D.  */
       if (d_option.deps_filename_user)
@@ -1293,7 +1301,7 @@ d_parse_file (void)
       else
 	deps_stream = stdout;
 
-      fprintf (deps_stream, "%s", buf.peekChars ());
+      fprintf (deps_stream, "%s", (char *) obstack_finish (&buffer));
 
       if (deps_stream != stdout
 	  && (ferror (deps_stream) || fclose (deps_stream)))
-- 
2.25.1


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

* [committed] d: Remove names of unused function parameters.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (2 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Remove dependency on front-end OutBuffer for diagnostic " Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Update code formatting in a consistent style Iain Buclaw
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces ARG_UNUSED and ATTRIBUTE_UNUSED with unnamed
parameters.  As the unused attribute was being used incorrectly.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-attribs.cc (handle_noreturn_attribute): Remove names of unused
	function parameters.
	(handle_leaf_attribute): Likewise.
	(handle_const_attribute): Likewise.
	(handle_malloc_attribute): Likewise.
	(handle_pure_attribute): Likewise.
	(handle_novops_attribute): Likewise.
	(handle_nonnull_attribute): Likewise.
	(handle_nothrow_attribute): Likewise.
	(handle_type_generic_attribute): Likewise.
	(handle_transaction_pure_attribute): Likewise.
	(handle_returns_twice_attribute): Likewise.
	(handle_fnspec_attribute): Likewise.
	(handle_always_inline_attribute): Likewise.
	(d_handle_noinline_attribute): Likewise.
	(d_handle_forceinline_attribute): Likewise.
	(d_handle_flatten_attribute): Likewise.
	(d_handle_noclone_attribute): Likewise.
	(d_handle_section_attribute): Likewise.
	(d_handle_alias_attribute): Likewise.
	(d_handle_weak_attribute): Likewise.
---
 gcc/d/d-attribs.cc | 96 +++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 65 deletions(-)

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 31137957c46..964f59f96f4 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -344,15 +344,15 @@ apply_user_attributes (Dsymbol *sym, tree node)
   input_location = saved_location;
 }
 
-/* Built-in attribute handlers.  */
+/* Built-in attribute handlers.
+   These functions take the arguments:
+   (tree *node, tree name, tree args, int flags, bool *no_add_attrs)  */
 
 /* Handle a "noreturn" attribute; arguments as in
    struct attribute_spec.handler.  */
 
 static tree
-handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
-			   tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			   bool * ARG_UNUSED (no_add_attrs))
+handle_noreturn_attribute (tree *node, tree, tree, int, bool *)
 {
   tree type = TREE_TYPE (*node);
 
@@ -374,9 +374,7 @@ handle_noreturn_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-handle_leaf_attribute (tree *node, tree name,
-		       tree ARG_UNUSED (args),
-		       int ARG_UNUSED (flags), bool *no_add_attrs)
+handle_leaf_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
 {
   if (TREE_CODE (*node) != FUNCTION_DECL)
     {
@@ -396,9 +394,7 @@ handle_leaf_attribute (tree *node, tree name,
    struct attribute_spec.handler.  */
 
 static tree
-handle_const_attribute (tree *node, tree ARG_UNUSED (name),
-			tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			bool * ARG_UNUSED (no_add_attrs))
+handle_const_attribute (tree *node, tree, tree, int, bool *)
 {
   tree type = TREE_TYPE (*node);
 
@@ -420,9 +416,7 @@ handle_const_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 tree
-handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
-			 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			 bool * ARG_UNUSED (no_add_attrs))
+handle_malloc_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL
 	      && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))));
@@ -434,9 +428,7 @@ handle_malloc_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
-		       tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-		       bool * ARG_UNUSED (no_add_attrs))
+handle_pure_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
   DECL_PURE_P (*node) = 1;
@@ -447,9 +439,7 @@ handle_pure_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
-			 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			 bool * ARG_UNUSED (no_add_attrs))
+handle_novops_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
   DECL_IS_NOVOPS (*node) = 1;
@@ -473,9 +463,7 @@ get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
 /* Handle the "nonnull" attribute.  */
 
 static tree
-handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
-			  tree args, int ARG_UNUSED (flags),
-			  bool * ARG_UNUSED (no_add_attrs))
+handle_nonnull_attribute (tree *node, tree, tree args, int, bool *)
 {
   tree type = *node;
 
@@ -525,9 +513,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
-			  tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			  bool * ARG_UNUSED (no_add_attrs))
+handle_nothrow_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
   TREE_NOTHROW (*node) = 1;
@@ -537,9 +523,7 @@ handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name),
 /* Handle a "type_generic" attribute.  */
 
 static tree
-handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
-			       tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-			       bool * ARG_UNUSED (no_add_attrs))
+handle_type_generic_attribute (tree *node, tree, tree, int, bool *)
 {
   /* Ensure we have a function type.  */
   gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
@@ -553,10 +537,7 @@ handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
 /* Handle a "transaction_pure" attribute.  */
 
 static tree
-handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
-				   tree ARG_UNUSED (args),
-				   int ARG_UNUSED (flags),
-				   bool * ARG_UNUSED (no_add_attrs))
+handle_transaction_pure_attribute (tree *node, tree, tree, int, bool *)
 {
   /* Ensure we have a function type.  */
   gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
@@ -567,10 +548,7 @@ handle_transaction_pure_attribute (tree *node, tree ARG_UNUSED (name),
 /* Handle a "returns_twice" attribute.  */
 
 static tree
-handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
-				tree ARG_UNUSED (args),
-				int ARG_UNUSED (flags),
-				bool * ARG_UNUSED (no_add_attrs))
+handle_returns_twice_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
 
@@ -583,9 +561,7 @@ handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 tree
-handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
-			 tree args, int ARG_UNUSED (flags),
-			 bool *no_add_attrs ATTRIBUTE_UNUSED)
+handle_fnspec_attribute (tree *, tree, tree args, int, bool *)
 {
   gcc_assert (args
 	      && TREE_CODE (TREE_VALUE (args)) == STRING_CST
@@ -597,23 +573,22 @@ handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-handle_always_inline_attribute (tree *node, tree ARG_UNUSED (name),
-				tree ARG_UNUSED (args), int ARG_UNUSED (flags),
-				bool *no_add_attrs ATTRIBUTE_UNUSED)
+handle_always_inline_attribute (tree *node, tree, tree, int, bool *)
 {
   gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
 
   return NULL_TREE;
 }
 
-/* Language specific attribute handlers.  */
+/* Language specific attribute handlers.
+   These functions take the arguments:
+   (tree *node, tree name, tree args, int flags, bool *no_add_attrs)  */
 
 /* Handle a "noinline" attribute.  */
 
 static tree
-d_handle_noinline_attribute (tree *node, tree name,
-			     tree ARG_UNUSED (args),
-			     int ARG_UNUSED (flags), bool *no_add_attrs)
+d_handle_noinline_attribute (tree *node, tree name, tree, int,
+			     bool *no_add_attrs)
 {
   Type *t = TYPE_LANG_FRONTEND (TREE_TYPE (*node));
 
@@ -631,9 +606,7 @@ d_handle_noinline_attribute (tree *node, tree name,
 /* Handle a "forceinline" attribute.  */
 
 static tree
-d_handle_forceinline_attribute (tree *node, tree name,
-				tree ARG_UNUSED (args),
-				int ARG_UNUSED (flags),
+d_handle_forceinline_attribute (tree *node, tree name, tree, int,
 				bool *no_add_attrs)
 {
   Type *t = TYPE_LANG_FRONTEND (TREE_TYPE (*node));
@@ -663,9 +636,8 @@ d_handle_forceinline_attribute (tree *node, tree name,
 /* Handle a "flatten" attribute.  */
 
 static tree
-d_handle_flatten_attribute (tree *node, tree name,
-			    tree args ATTRIBUTE_UNUSED,
-			    int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
+d_handle_flatten_attribute (tree *node, tree name, tree, int,
+			    bool *no_add_attrs)
 {
   Type *t = TYPE_LANG_FRONTEND (TREE_TYPE (*node));
 
@@ -701,10 +673,8 @@ d_handle_target_attribute (tree *node, tree name, tree args, int flags,
 /* Handle a "noclone" attribute.  */
 
 static tree
-d_handle_noclone_attribute (tree *node, tree name,
-				tree ARG_UNUSED (args),
-				int ARG_UNUSED (flags),
-				bool *no_add_attrs)
+d_handle_noclone_attribute (tree *node, tree name, tree, int,
+			    bool *no_add_attrs)
 {
   Type *t = TYPE_LANG_FRONTEND (TREE_TYPE (*node));
 
@@ -730,8 +700,8 @@ d_handle_noclone_attribute (tree *node, tree name,
    struct attribute_spec.handler.  */
 
 static tree
-d_handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
-			    int ARG_UNUSED (flags), bool *no_add_attrs)
+d_handle_section_attribute (tree *node, tree, tree args, int,
+			    bool *no_add_attrs)
 {
   tree decl = *node;
 
@@ -791,9 +761,8 @@ d_handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
    struct attribute_spec.handler.  */
 
 static tree
-d_handle_alias_attribute (tree *node, tree ARG_UNUSED (name),
-			  tree args, int ARG_UNUSED (flags),
-			  bool *no_add_attrs ATTRIBUTE_UNUSED)
+d_handle_alias_attribute (tree *node, tree name, tree args, int,
+			  bool *no_add_attrs)
 {
   tree decl = *node;
 
@@ -850,10 +819,7 @@ d_handle_alias_attribute (tree *node, tree ARG_UNUSED (name),
    struct attribute_spec.handler.  */
 
 static tree
-d_handle_weak_attribute (tree *node, tree name,
-			 tree ARG_UNUSED (args),
-			 int ARG_UNUSED (flags),
-			 bool * ARG_UNUSED (no_add_attrs))
+d_handle_weak_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
 {
   if (TREE_CODE (*node) == FUNCTION_DECL
       && DECL_DECLARED_INLINE_P (*node))
-- 
2.25.1


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

* [committed] d: Update code formatting in a consistent style.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (3 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Remove names of unused function parameters Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Use new isTypeXxxx helpers where possible Iain Buclaw
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch is a mechanical update of various formatting to make it
consistent throughout the D front-end.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-attribs.cc: Update code formatting in a consistant style.
	* d-builtins.cc: Likewise.
	* d-codegen.cc: Likewise.
	* d-compiler.cc: Likewise.
	* d-convert.cc: Likewise.
	* d-diagnostic.cc: Likewise.
	* d-frontend.cc: Likewise.
	* d-lang.cc: Likewise.
	* d-longdouble.cc: Likewise.
	* d-port.cc: Likewise.
	* d-spec.cc: Likewise.
	* d-tree.h: Likewise.
	* decl.cc: Likewise.
	* expr.cc: Likewise.
	* longdouble.h: Likewise.
	* modules.cc: Likewise.
	* toir.cc: Likewise.
	* typeinfo.cc: Likewise.
---
 gcc/d/d-attribs.cc    | 10 ++++-----
 gcc/d/d-builtins.cc   |  8 ++++----
 gcc/d/d-codegen.cc    | 26 +++++++++++------------
 gcc/d/d-compiler.cc   |  2 +-
 gcc/d/d-convert.cc    |  2 +-
 gcc/d/d-diagnostic.cc | 30 +++++++++++++--------------
 gcc/d/d-frontend.cc   |  2 +-
 gcc/d/d-lang.cc       | 16 +++++++--------
 gcc/d/d-longdouble.cc | 16 +++++++--------
 gcc/d/d-port.cc       |  8 ++++----
 gcc/d/d-spec.cc       |  2 +-
 gcc/d/d-tree.h        | 10 ++++-----
 gcc/d/decl.cc         | 10 ++++-----
 gcc/d/expr.cc         | 18 ++++++++--------
 gcc/d/longdouble.h    | 48 +++++++++++++++++++++----------------------
 gcc/d/modules.cc      | 32 ++++++++++++++---------------
 gcc/d/toir.cc         | 27 ++++++++++++------------
 gcc/d/typeinfo.cc     |  4 ++--
 18 files changed, 136 insertions(+), 135 deletions(-)

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 79938075a7c..31137957c46 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -254,7 +254,7 @@ build_attributes (Expressions *eattrs)
 	continue;
 
       /* Attribute symbol must come from the `gcc.attribute' module.  */
-      Dsymbol *mod = (Dsymbol*) sym->getModule ();
+      Dsymbol *mod = (Dsymbol *) sym->getModule ();
       if (!(strcmp (mod->toChars (), "attribute") == 0
 	    && mod->parent != NULL
 	    && strcmp (mod->parent->toChars (), "gcc") == 0
@@ -643,7 +643,7 @@ d_handle_forceinline_attribute (tree *node, tree name,
       tree attributes = DECL_ATTRIBUTES (*node);
 
       /* Push attribute always_inline.  */
-      if (! lookup_attribute ("always_inline", attributes))
+      if (!lookup_attribute ("always_inline", attributes))
 	DECL_ATTRIBUTES (*node) = tree_cons (get_identifier ("always_inline"),
 					     NULL_TREE, attributes);
 
@@ -692,7 +692,7 @@ d_handle_target_attribute (tree *node, tree name, tree args, int flags,
       warning (OPT_Wattributes, "%qE attribute ignored", name);
       *no_add_attrs = true;
     }
-  else if (! targetm.target_option.valid_attribute_p (*node, name, args, flags))
+  else if (!targetm.target_option.valid_attribute_p (*node, name, args, flags))
     *no_add_attrs = true;
 
   return NULL_TREE;
@@ -713,7 +713,7 @@ d_handle_noclone_attribute (tree *node, tree name,
       tree attributes = DECL_ATTRIBUTES (*node);
 
       /* Push attribute noclone.  */
-      if (! lookup_attribute ("noclone", attributes))
+      if (!lookup_attribute ("noclone", attributes))
 	DECL_ATTRIBUTES (*node) = tree_cons (get_identifier ("noclone"),
 					     NULL_TREE, attributes);
     }
@@ -810,7 +810,7 @@ d_handle_alias_attribute (tree *node, tree ARG_UNUSED (name),
       /* A static variable declaration is always a tentative definition,
 	 but the alias is a non-tentative definition which overrides.  */
       || (TREE_CODE (decl) != FUNCTION_DECL
-	  && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
+	  && !TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
     {
       error ("%q+D defined both normally and as %qE attribute", decl, name);
       *no_add_attrs = true;
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 75eaa6b8a73..6272ab83a76 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -42,9 +42,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "d-target.h"
 
 
-static GTY(()) vec<tree, va_gc> *gcc_builtins_functions = NULL;
-static GTY(()) vec<tree, va_gc> *gcc_builtins_libfuncs = NULL;
-static GTY(()) vec<tree, va_gc> *gcc_builtins_types = NULL;
+static GTY(()) vec <tree, va_gc> *gcc_builtins_functions = NULL;
+static GTY(()) vec <tree, va_gc> *gcc_builtins_libfuncs = NULL;
+static GTY(()) vec <tree, va_gc> *gcc_builtins_types = NULL;
 
 /* Record built-in types and their associated decls for re-use when
    generating the `gcc.builtins' module.  */
@@ -60,7 +60,7 @@ struct builtin_data
   { }
 };
 
-static vec<builtin_data> builtin_converted_decls;
+static vec <builtin_data> builtin_converted_decls;
 
 /* Build D frontend type from tree TYPE type given.  This will set the
    back-end type symbol directly for complex types to save build_ctype()
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index b82e16fe79e..cea47315d0e 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -44,7 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Return the GCC location for the D frontend location LOC.  */
 
 location_t
-make_location_t (const Loc& loc)
+make_location_t (const Loc &loc)
 {
   location_t gcc_location = input_location;
 
@@ -241,7 +241,7 @@ build_integer_cst (dinteger_t value, tree type)
 /* Build REAL_CST of type TOTYPE with the value VALUE.  */
 
 tree
-build_float_cst (const real_t& value, Type *totype)
+build_float_cst (const real_t &value, Type *totype)
 {
   real_t new_value;
   TypeBasic *tb = totype->isTypeBasic ();
@@ -293,7 +293,7 @@ tree
 d_array_value (tree type, tree len, tree data)
 {
   tree len_field, ptr_field;
-  vec<constructor_elt, va_gc> *ce = NULL;
+  vec <constructor_elt, va_gc> *ce = NULL;
 
   gcc_assert (TYPE_DYNAMIC_ARRAY (type));
   len_field = TYPE_FIELDS (type);
@@ -356,7 +356,7 @@ build_class_binfo (tree super, ClassDeclaration *cd)
    This function makes assumptions about interface layout.  */
 
 tree
-build_interface_binfo (tree super, ClassDeclaration *cd, unsigned& offset)
+build_interface_binfo (tree super, ClassDeclaration *cd, unsigned &offset)
 {
   tree binfo = make_tree_binfo (cd->baseclasses->length);
   tree ctype = build_ctype (cd->type);
@@ -421,7 +421,7 @@ build_delegate_cst (tree method, tree object, Type *type)
       TYPE_DELEGATE (ctype) = 1;
     }
 
-  vec<constructor_elt, va_gc> *ce = NULL;
+  vec <constructor_elt, va_gc> *ce = NULL;
   CONSTRUCTOR_APPEND_ELT (ce, TYPE_FIELDS (ctype), object);
   CONSTRUCTOR_APPEND_ELT (ce, TREE_CHAIN (TYPE_FIELDS (ctype)), method);
 
@@ -445,7 +445,7 @@ build_method_call (tree callee, tree object, Type *type)
 /* Extract callee and object from T and return in to CALLEE and OBJECT.  */
 
 void
-extract_from_method_call (tree t, tree& callee, tree& object)
+extract_from_method_call (tree t, tree &callee, tree &object)
 {
   gcc_assert (METHOD_CALL_EXPR (t));
   object = CONSTRUCTOR_ELT (t, 0)->value;
@@ -1094,13 +1094,13 @@ build_array_struct_comparison (tree_code code, StructDeclaration *sd,
    matches the layout of TYPE.  */
 
 tree
-build_struct_literal (tree type, vec<constructor_elt, va_gc> *init)
+build_struct_literal (tree type, vec <constructor_elt, va_gc> *init)
 {
   /* If the initializer was empty, use default zero initialization.  */
   if (vec_safe_is_empty (init))
     return build_constructor (type, NULL);
 
-  vec<constructor_elt, va_gc> *ve = NULL;
+  vec <constructor_elt, va_gc> *ve = NULL;
   HOST_WIDE_INT offset = 0;
   bool constant_p = true;
   bool finished = false;
@@ -1685,7 +1685,7 @@ build_array_from_val (Type *type, tree val)
     val = build_array_from_val (type->nextOf (), val);
 
   size_t dims = type->isTypeSArray ()->dim->toInteger ();
-  vec<constructor_elt, va_gc> *elms = NULL;
+  vec <constructor_elt, va_gc> *elms = NULL;
   vec_safe_reserve (elms, dims);
 
   val = d_convert (etype, val);
@@ -1737,7 +1737,7 @@ build_array_bounds_call (const Loc &loc)
    If INCLUSIVE, we allow INDEX == LEN to return true also.  */
 
 tree
-build_bounds_condition (const Loc& loc, tree index, tree len, bool inclusive)
+build_bounds_condition (const Loc &loc, tree index, tree len, bool inclusive)
 {
   if (!array_bounds_check ())
     return index;
@@ -1873,7 +1873,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
     }
 
   /* Build the argument list for the call.  */
-  vec<tree, va_gc> *args = NULL;
+  vec <tree, va_gc> *args = NULL;
   tree saved_args = NULL_TREE;
 
   /* If this is a delegate call or a nested function being called as
@@ -1976,7 +1976,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
 /* Builds a call to AssertError or AssertErrorMsg.  */
 
 tree
-d_assert_call (const Loc& loc, libcall_fn libcall, tree msg)
+d_assert_call (const Loc &loc, libcall_fn libcall, tree msg)
 {
   tree file;
   tree line = size_int (loc.linnum);
@@ -2202,7 +2202,7 @@ get_frame_for_symbol (Dsymbol *sym)
 	      tree fields = TYPE_FIELDS (type);
 	      /* The `this' field comes immediately after the `__chain'.  */
 	      tree thisfield = chain_index (1, fields);
-	      vec<constructor_elt, va_gc> *ve = NULL;
+	      vec <constructor_elt, va_gc> *ve = NULL;
 
 	      tree framefields = TYPE_FIELDS (FRAMEINFO_TYPE (ffo));
 	      frame_ref = build_deref (frame_ref);
diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index 41b3b53207a..ffa7f78c82e 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -89,7 +89,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
     {
       /* Build array as VECTOR_CST, assumes EXPR is constant.  */
       Expressions *elements = expr->isArrayLiteralExp ()->elements;
-      vec<constructor_elt, va_gc> *elms = NULL;
+      vec <constructor_elt, va_gc> *elms = NULL;
 
       vec_safe_reserve (elms, elements->length);
       for (size_t i = 0; i < elements->length; i++)
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index 80101f17b1d..5e3e855b2cb 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -622,7 +622,7 @@ convert_for_assignment (tree expr, Type *etype, Type *totype)
 	  tree ctor = build_constructor (build_ctype (totype), NULL);
 	  if (count)
 	    {
-	      vec<constructor_elt, va_gc> *ce = NULL;
+	      vec <constructor_elt, va_gc> *ce = NULL;
 	      tree index = build2 (RANGE_EXPR, build_ctype (Type::tsize_t),
 				   size_zero_node, size_int (count - 1));
 	      tree value = convert_for_assignment (expr, etype, sa_type->next);
diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc
index ee5f6e23df2..7eeb41312cf 100644
--- a/gcc/d/d-diagnostic.cc
+++ b/gcc/d/d-diagnostic.cc
@@ -119,7 +119,7 @@ expand_d_format (const char *format)
    front-end, which does not get translated by the gcc diagnostic routines.  */
 
 static void ATTRIBUTE_GCC_DIAG(3,0)
-d_diagnostic_report_diagnostic (const Loc& loc, int opt, const char *format,
+d_diagnostic_report_diagnostic (const Loc &loc, int opt, const char *format,
 				va_list ap, diagnostic_t kind, bool verbatim)
 {
   va_list argp;
@@ -159,7 +159,7 @@ d_diagnostic_report_diagnostic (const Loc& loc, int opt, const char *format,
    error count.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-error (const Loc& loc, const char *format, ...)
+error (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -168,7 +168,7 @@ error (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-verror (const Loc& loc, const char *format, va_list ap,
+verror (const Loc &loc, const char *format, va_list ap,
 	const char *prefix1, const char *prefix2, const char *)
 {
   if (!global.gag || global.params.showGaggedErrors)
@@ -199,7 +199,7 @@ verror (const Loc& loc, const char *format, va_list ap,
    This doesn't increase the global error count.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-errorSupplemental (const Loc& loc, const char *format, ...)
+errorSupplemental (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -208,7 +208,7 @@ errorSupplemental (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-verrorSupplemental (const Loc& loc, const char *format, va_list ap)
+verrorSupplemental (const Loc &loc, const char *format, va_list ap)
 {
   if (global.gag && !global.params.showGaggedErrors)
     return;
@@ -220,7 +220,7 @@ verrorSupplemental (const Loc& loc, const char *format, va_list ap)
    global warning count.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-warning (const Loc& loc, const char *format, ...)
+warning (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -229,7 +229,7 @@ warning (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-vwarning (const Loc& loc, const char *format, va_list ap)
+vwarning (const Loc &loc, const char *format, va_list ap)
 {
   if (!global.gag && global.params.warnings != DIAGNOSTICoff)
     {
@@ -245,7 +245,7 @@ vwarning (const Loc& loc, const char *format, va_list ap)
    LOC.  This doesn't increase the global warning count.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-warningSupplemental (const Loc& loc, const char *format, ...)
+warningSupplemental (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -254,7 +254,7 @@ warningSupplemental (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-vwarningSupplemental (const Loc& loc, const char *format, va_list ap)
+vwarningSupplemental (const Loc &loc, const char *format, va_list ap)
 {
   if (global.params.warnings == DIAGNOSTICoff || global.gag)
     return;
@@ -267,7 +267,7 @@ vwarningSupplemental (const Loc& loc, const char *format, va_list ap)
    error count depending on how deprecations are treated.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-deprecation (const Loc& loc, const char *format, ...)
+deprecation (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -276,7 +276,7 @@ deprecation (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecation (const Loc& loc, const char *format, va_list ap,
+vdeprecation (const Loc &loc, const char *format, va_list ap,
 	      const char *prefix1, const char *prefix2)
 {
   if (global.params.useDeprecated == DIAGNOSTICerror)
@@ -303,7 +303,7 @@ vdeprecation (const Loc& loc, const char *format, va_list ap,
    location LOC.  This does not increase the global error count.  */
 
 void ATTRIBUTE_GCC_DIAG(2,3)
-deprecationSupplemental (const Loc& loc, const char *format, ...)
+deprecationSupplemental (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -312,7 +312,7 @@ deprecationSupplemental (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecationSupplemental (const Loc& loc, const char *format, va_list ap)
+vdeprecationSupplemental (const Loc &loc, const char *format, va_list ap)
 {
   if (global.params.useDeprecated == DIAGNOSTICerror)
     verrorSupplemental (loc, format, ap);
@@ -323,7 +323,7 @@ vdeprecationSupplemental (const Loc& loc, const char *format, va_list ap)
 /* Print a verbose message with explicit location LOC.  */
 
 void ATTRIBUTE_GCC_DIAG(2, 3)
-message (const Loc& loc, const char *format, ...)
+message (const Loc &loc, const char *format, ...)
 {
   va_list ap;
   va_start (ap, format);
@@ -332,7 +332,7 @@ message (const Loc& loc, const char *format, ...)
 }
 
 void ATTRIBUTE_GCC_DIAG(2,0)
-vmessage (const Loc& loc, const char *format, va_list ap)
+vmessage (const Loc &loc, const char *format, va_list ap)
 {
   d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, true);
 }
diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc
index 7434819d644..3b9fc1aaf2a 100644
--- a/gcc/d/d-frontend.cc
+++ b/gcc/d/d-frontend.cc
@@ -125,7 +125,7 @@ Loc::toChars (void) const
 }
 
 bool
-Loc::equals (const Loc& loc)
+Loc::equals (const Loc &loc)
 {
   if (this->linnum != loc.linnum || this->charnum != loc.charnum)
     return false;
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index dd5a83cb4fe..82e24de8cd1 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -95,7 +95,7 @@ struct binding_level *global_binding_level;
 static GTY(()) tree global_context;
 
 /* Array of all global declarations to pass back to the middle-end.  */
-static GTY(()) vec<tree, va_gc> *global_declarations;
+static GTY(()) vec <tree, va_gc> *global_declarations;
 
 /* Support for GCC-style command-line make dependency generation.
    Adds TARGET to the make dependencies target buffer.
@@ -366,7 +366,7 @@ d_init (void)
   Objc::_init ();
 
   /* Back-end init.  */
-  global_binding_level = ggc_cleared_alloc<binding_level> ();
+  global_binding_level = ggc_cleared_alloc <binding_level> ();
   current_binding_level = global_binding_level;
 
   /* This allows the code in d-builtins.cc to not have to worry about
@@ -1142,7 +1142,7 @@ d_parse_file (void)
       unsigned errors = global.startGagging ();
       Module *m = Module::load (Loc (), NULL, Identifier::idPool ("__main"));
 
-      if (! global.endGagging (errors))
+      if (!global.endGagging (errors))
 	{
 	  m->importedFrom = m;
 	  modules.push (m);
@@ -1774,7 +1774,7 @@ d_tree_node_structure (lang_tree_node *t)
 struct lang_type *
 build_lang_type (Type *t)
 {
-  struct lang_type *lt = ggc_cleared_alloc<struct lang_type> ();
+  struct lang_type *lt = ggc_cleared_alloc <struct lang_type> ();
   lt->type = t;
   return lt;
 }
@@ -1788,11 +1788,11 @@ build_lang_decl (Declaration *d)
      there's no associated frontend symbol to refer to (yet).  If the symbol
      appears later in the compilation, then the slot will be re-used.  */
   if (d == NULL)
-    return ggc_cleared_alloc<struct lang_decl> ();
+    return ggc_cleared_alloc <struct lang_decl> ();
 
   struct lang_decl *ld = (d->csym) ? DECL_LANG_SPECIFIC (d->csym) : NULL;
   if (ld == NULL)
-    ld = ggc_cleared_alloc<struct lang_decl> ();
+    ld = ggc_cleared_alloc <struct lang_decl> ();
 
   if (ld->decl == NULL)
     ld->decl = d;
@@ -1806,10 +1806,10 @@ build_lang_decl (Declaration *d)
 static void
 d_dup_lang_specific_decl (tree node)
 {
-  if (! DECL_LANG_SPECIFIC (node))
+  if (!DECL_LANG_SPECIFIC (node))
     return;
 
-  struct lang_decl *ld = ggc_alloc<struct lang_decl> ();
+  struct lang_decl *ld = ggc_alloc <struct lang_decl> ();
   memcpy (ld, DECL_LANG_SPECIFIC (node), sizeof (struct lang_decl));
   DECL_LANG_SPECIFIC (node) = ld;
 }
diff --git a/gcc/d/d-longdouble.cc b/gcc/d/d-longdouble.cc
index a8c90cf2210..04623d0a30a 100644
--- a/gcc/d/d-longdouble.cc
+++ b/gcc/d/d-longdouble.cc
@@ -49,7 +49,7 @@ longdouble::normalize (void)
 /* Assign a real_value to a longdouble type.  */
 
 void
-longdouble::set (real_value& d)
+longdouble::set (real_value &d)
 {
   real_convert (&this->rv (), TYPE_MODE (long_double_type_node), &d);
 }
@@ -117,7 +117,7 @@ longdouble::to_bool (void) const
 /* Overload numeric operators for longdouble types.  */
 
 longdouble
-longdouble::add (const longdouble& r) const
+longdouble::add (const longdouble &r) const
 {
   longdouble x;
   real_arithmetic (&x.rv (), PLUS_EXPR, &this->rv (), &r.rv ());
@@ -125,7 +125,7 @@ longdouble::add (const longdouble& r) const
 }
 
 longdouble
-longdouble::sub (const longdouble& r) const
+longdouble::sub (const longdouble &r) const
 {
   longdouble x;
   real_arithmetic (&x.rv (), MINUS_EXPR, &this->rv (), &r.rv ());
@@ -133,7 +133,7 @@ longdouble::sub (const longdouble& r) const
 }
 
 longdouble
-longdouble::mul (const longdouble& r) const
+longdouble::mul (const longdouble &r) const
 {
   longdouble x;
   real_arithmetic (&x.rv (), MULT_EXPR, &this->rv (), &r.rv ());
@@ -141,7 +141,7 @@ longdouble::mul (const longdouble& r) const
 }
 
 longdouble
-longdouble::div (const longdouble& r) const
+longdouble::div (const longdouble &r) const
 {
   longdouble x;
   real_arithmetic (&x.rv (), RDIV_EXPR, &this->rv (), &r.rv ());
@@ -149,7 +149,7 @@ longdouble::div (const longdouble& r) const
 }
 
 longdouble
-longdouble::mod (const longdouble& r) const
+longdouble::mod (const longdouble &r) const
 {
   longdouble x;
   real_value q;
@@ -186,7 +186,7 @@ longdouble::neg (void) const
 /* Overload equality operators for longdouble types.  */
 
 int
-longdouble::cmp (const longdouble& r) const
+longdouble::cmp (const longdouble &r) const
 {
   if (real_compare (LT_EXPR, &this->rv (), &r.rv ()))
     return -1;
@@ -198,7 +198,7 @@ longdouble::cmp (const longdouble& r) const
 }
 
 int
-longdouble::equals (const longdouble& r) const
+longdouble::equals (const longdouble &r) const
 {
   return real_compare (EQ_EXPR, &this->rv (), &r.rv ());
 }
diff --git a/gcc/d/d-port.cc b/gcc/d/d-port.cc
index d49bb1ba8f3..d09c33e4ab0 100644
--- a/gcc/d/d-port.cc
+++ b/gcc/d/d-port.cc
@@ -99,7 +99,7 @@ Port::isFloat64LiteralOutOfRange (const char *buffer)
 unsigned
 Port::readwordLE (const void *buffer)
 {
-  const unsigned char *p = (const unsigned char*) buffer;
+  const unsigned char *p = (const unsigned char *) buffer;
 
   return ((unsigned) p[1] << 8) | (unsigned) p[0];
 }
@@ -109,7 +109,7 @@ Port::readwordLE (const void *buffer)
 unsigned
 Port::readwordBE (const void *buffer)
 {
-  const unsigned char *p = (const unsigned char*) buffer;
+  const unsigned char *p = (const unsigned char *) buffer;
 
   return ((unsigned) p[0] << 8) | (unsigned) p[1];
 }
@@ -119,7 +119,7 @@ Port::readwordBE (const void *buffer)
 unsigned
 Port::readlongLE (const void *buffer)
 {
-  const unsigned char *p = (const unsigned char*) buffer;
+  const unsigned char *p = (const unsigned char *) buffer;
 
   return (((unsigned) p[3] << 24)
 	  | ((unsigned) p[2] << 16)
@@ -132,7 +132,7 @@ Port::readlongLE (const void *buffer)
 unsigned
 Port::readlongBE (const void *buffer)
 {
-  const unsigned char *p = (const unsigned char*) buffer;
+  const unsigned char *p = (const unsigned char *) buffer;
 
   return (((unsigned) p[0] << 24)
 	  | ((unsigned) p[1] << 16)
diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
index f4744763ab6..cde43e91863 100644
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -56,7 +56,7 @@ enum phobos_action
   /* libgphobos is needed and should be linked statically.  */
   PHOBOS_STATIC,
   /* libgphobos is needed and should be linked dynamically.  */
-  PHOBOS_DYNAMIC,
+  PHOBOS_DYNAMIC
 };
 
 static phobos_action phobos_library = PHOBOS_DEFAULT;
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index dd38b732837..4ae38d187d7 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -41,7 +41,7 @@ struct Scope;
 struct Loc;
 
 template <typename TYPE> struct Array;
-typedef Array<Expression *> Expressions;
+typedef Array <Expression *> Expressions;
 
 /* Usage of TREE_LANG_FLAG_?:
    0: METHOD_CALL_EXPR
@@ -234,13 +234,13 @@ struct GTY(()) language_function
 
   /* Stack of statement lists being collected while we are
      compiling the function.  */
-  vec<tree, va_gc> *stmt_list;
+  vec <tree, va_gc> *stmt_list;
 
   /* Variables that are in scope that will need destruction later.  */
-  vec<tree, va_gc> *vars_in_scope;
+  vec <tree, va_gc> *vars_in_scope;
 
   /* Table of all used or defined labels in the function.  */
-  hash_map<Statement *, d_label_entry> *labels;
+  hash_map <Statement *, d_label_entry> *labels;
 };
 
 /* The D front end types have not been integrated into the GCC garbage
@@ -536,7 +536,7 @@ extern tree build_struct_comparison (tree_code, StructDeclaration *,
 				     tree, tree);
 extern tree build_array_struct_comparison (tree_code, StructDeclaration *,
 					   tree, tree, tree);
-extern tree build_struct_literal (tree, vec<constructor_elt, va_gc> *);
+extern tree build_struct_literal (tree, vec <constructor_elt, va_gc> *);
 extern tree component_ref (tree, tree);
 extern tree build_assign (tree_code, tree, tree);
 extern tree modify_expr (tree, tree);
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index f43b334aac7..ea6614fb714 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -63,7 +63,7 @@ const char *
 d_mangle_decl (Dsymbol *decl)
 {
   if (decl->isFuncDeclaration ())
-    return mangleExact ((FuncDeclaration *)decl);
+    return mangleExact ((FuncDeclaration *) decl);
   else
     {
       OutBuffer buf;
@@ -511,7 +511,7 @@ public:
     d_finish_decl (d->csym);
 
     /* Put out the vtbl[].  */
-    vec<constructor_elt, va_gc> *elms = NULL;
+    vec <constructor_elt, va_gc> *elms = NULL;
 
     /* First entry is ClassInfo reference.  */
     if (d->vtblOffset ())
@@ -521,7 +521,7 @@ public:
       {
 	FuncDeclaration *fd = d->vtbl[i]->isFuncDeclaration ();
 
-	if (fd && (fd->fbody || !d->isAbstract()))
+	if (fd && (fd->fbody || !d->isAbstract ()))
 	  {
 	    CONSTRUCTOR_APPEND_ELT (elms, size_int (i),
 				    build_address (get_symbol_decl (fd)));
@@ -1897,7 +1897,7 @@ start_function (FuncDeclaration *fd)
   else
     cfun->function_end_locus = DECL_SOURCE_LOCATION (fndecl);
 
-  cfun->language = ggc_cleared_alloc<language_function> ();
+  cfun->language = ggc_cleared_alloc <language_function> ();
   cfun->language->function = fd;
 
   /* Default chain value is `null' unless parent found.  */
@@ -2097,7 +2097,7 @@ build_class_instance (ClassReferenceExp *exp)
 {
   ClassDeclaration *cd = exp->originalClass ();
   tree type = TREE_TYPE (build_ctype (exp->value->stype));
-  vec<constructor_elt, va_gc> *ve = NULL;
+  vec <constructor_elt, va_gc> *ve = NULL;
 
   /* The set base vtable field.  */
   tree vptr = build_address (get_vtable_decl (cd));
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index e1842cc6fee..7a209fbe733 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -695,7 +695,7 @@ public:
 	tree var = build_local_temp (make_array_type (targselem, ndims));
 
 	/* Loop through each concatenation from right to left.  */
-	vec<constructor_elt, va_gc> *elms = NULL;
+	vec <constructor_elt, va_gc> *elms = NULL;
 	CatExp *ce = e;
 	int dim = ndims - 1;
 
@@ -2465,7 +2465,7 @@ public:
 	    /* Multidimensional array allocations.  */
 	    tree tarray = make_array_type (Type::tsize_t, e->arguments->length);
 	    tree var = build_local_temp (tarray);
-	    vec<constructor_elt, va_gc> *elms = NULL;
+	    vec <constructor_elt, va_gc> *elms = NULL;
 
 	    /* Get the base element type for the array, generating the
 	       initializer for the dims parameter along the way.  */
@@ -2591,7 +2591,7 @@ public:
     if (tb->ty == Tsarray)
       {
 	/* Turn the string into a constructor for the static array.  */
-	vec<constructor_elt, va_gc> *elms = NULL;
+	vec <constructor_elt, va_gc> *elms = NULL;
 	vec_safe_reserve (elms, e->len);
 	tree etype = TREE_TYPE (type);
 
@@ -2677,7 +2677,7 @@ public:
 
     /* Build an expression that assigns the expressions in ELEMENTS to
        a constructor.  */
-    vec<constructor_elt, va_gc> *elms = NULL;
+    vec <constructor_elt, va_gc> *elms = NULL;
     vec_safe_reserve (elms, e->elements->length);
     bool constant_p = true;
     tree saved_elems = NULL_TREE;
@@ -2784,7 +2784,7 @@ public:
 
     /* Build an expression that assigns all expressions in KEYS
        to a constructor.  */
-    vec<constructor_elt, va_gc> *kelts = NULL;
+    vec <constructor_elt, va_gc> *kelts = NULL;
     vec_safe_reserve (kelts, e->keys->length);
     for (size_t i = 0; i < e->keys->length; i++)
       {
@@ -2797,7 +2797,7 @@ public:
     tree akeys = build_constructor (tkeys, kelts);
 
     /* Do the same with all expressions in VALUES.  */
-    vec<constructor_elt, va_gc> *velts = NULL;
+    vec <constructor_elt, va_gc> *velts = NULL;
     vec_safe_reserve (velts, e->values->length);
     for (size_t i = 0; i < e->values->length; i++)
       {
@@ -2822,7 +2822,7 @@ public:
 
     /* Return an associative array pointed to by MEM.  */
     tree aatype = build_ctype (ta);
-    vec<constructor_elt, va_gc> *ce = NULL;
+    vec <constructor_elt, va_gc> *ce = NULL;
     CONSTRUCTOR_APPEND_ELT (ce, TYPE_FIELDS (aatype), mem);
 
     this->result_ = build_nop (build_ctype (e->type),
@@ -2850,7 +2850,7 @@ public:
 
     /* Build a constructor that assigns the expressions in ELEMENTS
        at each field index that has been filled in.  */
-    vec<constructor_elt, va_gc> *ve = NULL;
+    vec <constructor_elt, va_gc> *ve = NULL;
     tree saved_elems = NULL_TREE;
 
     /* CTFE may fill the hidden pointer by NullExp.  */
@@ -2961,7 +2961,7 @@ public:
     if (e->e1->op == TOKarrayliteral)
       {
 	ArrayLiteralExp *ale = e->e1->isArrayLiteralExp ();
-	vec<constructor_elt, va_gc> *elms = NULL;
+	vec <constructor_elt, va_gc> *elms = NULL;
 	bool constant_p = true;
 
 	vec_safe_reserve (elms, ale->elements->length);
diff --git a/gcc/d/longdouble.h b/gcc/d/longdouble.h
index 0d91a991c3b..905e682c9ca 100644
--- a/gcc/d/longdouble.h
+++ b/gcc/d/longdouble.h
@@ -25,21 +25,21 @@ struct longdouble
 {
 public:
   /* Return the hidden real_value from the longdouble type.  */
-  const real_value& rv (void) const
+  const real_value &rv (void) const
   { return *(const real_value *) this; }
 
-  real_value& rv (void)
+  real_value &rv (void)
   { return *(real_value *) this; }
 
   /* Normalize the value to be the precision supported by target.  */
   longdouble normalize (void);
 
   /* No constructor to be able to use this class in a union.  */
-  template<typename T> longdouble& operator = (T x)
+  template <typename T> longdouble &operator = (T x)
   { set (x); return *this; }
 
   /* Lvalue operators.  */
-  void set (real_value& d);
+  void set (real_value &d);
   void set (int32_t d);
   void set (int64_t d);
   void set (uint32_t d);
@@ -67,51 +67,51 @@ public:
   { return this->to_bool (); }
 
   /* Arithmetic operators.  */
-  longdouble add (const longdouble& r) const;
-  longdouble sub (const longdouble& r) const;
-  longdouble mul (const longdouble& r) const;
-  longdouble div (const longdouble& r) const;
-  longdouble mod (const longdouble& r) const;
+  longdouble add (const longdouble &r) const;
+  longdouble sub (const longdouble &r) const;
+  longdouble mul (const longdouble &r) const;
+  longdouble div (const longdouble &r) const;
+  longdouble mod (const longdouble &r) const;
   longdouble neg () const;
 
-  longdouble operator + (const longdouble& r)
+  longdouble operator + (const longdouble &r)
   { return this->add (r); }
 
-  longdouble operator - (const longdouble& r)
+  longdouble operator - (const longdouble &r)
   { return this->sub (r); }
 
-  longdouble operator * (const longdouble& r)
+  longdouble operator * (const longdouble &r)
   { return this->mul (r); }
 
-  longdouble operator / (const longdouble& r)
+  longdouble operator / (const longdouble &r)
   { return this->div (r); }
 
-  longdouble operator % (const longdouble& r)
+  longdouble operator % (const longdouble &r)
   { return this->mod (r); }
 
-  longdouble operator -()
+  longdouble operator - (void)
   { return this->neg (); }
 
   /* Comparison operators.  */
-  int cmp (const longdouble& t) const;
-  int equals (const longdouble& t) const;
+  int cmp (const longdouble &t) const;
+  int equals (const longdouble &t) const;
 
-  bool operator < (const longdouble& r)
+  bool operator < (const longdouble &r)
   { return this->cmp (r) < 0; }
 
-  bool operator <= (const longdouble& r)
+  bool operator <= (const longdouble &r)
   { return this->cmp (r) <= 0; }
 
-  bool operator > (const longdouble& r)
+  bool operator > (const longdouble &r)
   { return this->cmp (r) > 0; }
 
-  bool operator >= (const longdouble& r)
+  bool operator >= (const longdouble &r)
   { return this->cmp (r) >= 0; }
 
-  bool operator == (const longdouble& r)
+  bool operator == (const longdouble &r)
   { return this->equals (r); }
 
-  bool operator != (const longdouble& r)
+  bool operator != (const longdouble &r)
   { return !this->equals (r); }
 
 private:
@@ -124,7 +124,7 @@ private:
 typedef longdouble volatile_longdouble;
 
 /* Use ldouble() to explicitly create a longdouble value.  */
-template<typename T>
+template <typename T>
 inline longdouble
 ldouble (T x)
 {
diff --git a/gcc/d/modules.cc b/gcc/d/modules.cc
index 79f42c68b10..4b48c19a90e 100644
--- a/gcc/d/modules.cc
+++ b/gcc/d/modules.cc
@@ -76,15 +76,15 @@ static tree stop_minfo_node;
 
 struct GTY(()) module_info
 {
-  vec<tree, va_gc> *ctors;
-  vec<tree, va_gc> *dtors;
-  vec<tree, va_gc> *ctorgates;
+  vec <tree, va_gc> *ctors;
+  vec <tree, va_gc> *dtors;
+  vec <tree, va_gc> *ctorgates;
 
-  vec<tree, va_gc> *sharedctors;
-  vec<tree, va_gc> *shareddtors;
-  vec<tree, va_gc> *sharedctorgates;
+  vec <tree, va_gc> *sharedctors;
+  vec <tree, va_gc> *shareddtors;
+  vec <tree, va_gc> *sharedctorgates;
 
-  vec<tree, va_gc> *unitTests;
+  vec <tree, va_gc> *unitTests;
 };
 
 /* These must match the values in libdruntime/object_.d.  */
@@ -122,8 +122,8 @@ static Module *current_module_decl;
 
 /* Static constructors and destructors (not D `static this').  */
 
-static GTY(()) vec<tree, va_gc> *static_ctor_list;
-static GTY(()) vec<tree, va_gc> *static_dtor_list;
+static GTY(()) vec <tree, va_gc> *static_ctor_list;
+static GTY(()) vec <tree, va_gc> *static_dtor_list;
 
 /* Returns an internal function identified by IDENT.  This is used
    by both module initialization and dso handlers.  */
@@ -180,8 +180,8 @@ build_internal_fn (tree ident, tree expr)
    all variables in GATES, then calls the list of functions in FUNCTIONS.  */
 
 static tree
-build_funcs_gates_fn (tree ident, vec<tree, va_gc> *functions,
-		      vec<tree, va_gc> *gates)
+build_funcs_gates_fn (tree ident, vec <tree, va_gc> *functions,
+		      vec <tree, va_gc> *gates)
 {
   tree expr_list = NULL_TREE;
 
@@ -365,7 +365,7 @@ build_dso_cdtor_fn (bool ctor_p)
   tree dso_type = get_compiler_dso_type ();
   tree dso = build_local_temp (dso_type);
 
-  vec<constructor_elt, va_gc> *ve = NULL;
+  vec <constructor_elt, va_gc> *ve = NULL;
   CONSTRUCTOR_APPEND_ELT (ve, NULL_TREE, build_integer_cst (1, size_type_node));
   CONSTRUCTOR_APPEND_ELT (ve, NULL_TREE, build_address (dso_slot_node));
   CONSTRUCTOR_APPEND_ELT (ve, NULL_TREE, build_address (start_minfo_node));
@@ -465,7 +465,7 @@ register_moduleinfo (Module *decl, tree minfo)
    position.  No alignment is taken into account, all fields are packed.  */
 
 static void
-layout_moduleinfo_field (tree type, tree rec_type, HOST_WIDE_INT& offset)
+layout_moduleinfo_field (tree type, tree rec_type, HOST_WIDE_INT &offset)
 {
   tree field = create_field_decl (type, NULL, 1, 1);
   insert_aggregate_field (rec_type, field, offset);
@@ -603,7 +603,7 @@ layout_moduleinfo (Module *decl)
   /* Put out the two named fields in a ModuleInfo decl:
 	uint flags;
 	uint index;  */
-  vec<constructor_elt, va_gc> *minit = NULL;
+  vec <constructor_elt, va_gc> *minit = NULL;
 
   CONSTRUCTOR_APPEND_ELT (minit, NULL_TREE,
 			  build_integer_cst (flags, d_uint_type));
@@ -649,7 +649,7 @@ layout_moduleinfo (Module *decl)
 
   if (flags & MIimportedModules)
     {
-      vec<constructor_elt, va_gc> *elms = NULL;
+      vec <constructor_elt, va_gc> *elms = NULL;
       tree satype = make_array_type (Type::tvoidptr, aimports_dim);
       size_t idx = 0;
 
@@ -671,7 +671,7 @@ layout_moduleinfo (Module *decl)
 
   if (flags & MIlocalClasses)
     {
-      vec<constructor_elt, va_gc> *elms = NULL;
+      vec <constructor_elt, va_gc> *elms = NULL;
       tree satype = make_array_type (Type::tvoidptr, aclasses.length);
 
       for (size_t i = 0; i < aclasses.length; i++)
diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc
index b6f72092e5f..329efcdb40c 100644
--- a/gcc/d/toir.cc
+++ b/gcc/d/toir.cc
@@ -68,7 +68,7 @@ pop_binding_label (Statement * const &, d_label_entry *ent, binding_level *bl)
    go out of scope.  Queue them in LABELS.  */
 
 bool
-pop_label (Statement * const &, d_label_entry *ent, vec<tree> &labels)
+pop_label (Statement * const &, d_label_entry *ent, vec <tree> &labels)
 {
   if (!ent->bc_label)
     {
@@ -93,7 +93,7 @@ void
 push_binding_level (level_kind kind)
 {
   /* Add it to the front of currently active scopes stack.  */
-  binding_level *new_level = ggc_cleared_alloc<binding_level> ();
+  binding_level *new_level = ggc_cleared_alloc <binding_level> ();
   new_level->level_chain = current_binding_level;
   new_level->kind = kind;
 
@@ -103,8 +103,8 @@ push_binding_level (level_kind kind)
 static int
 cmp_labels (const void *p1, const void *p2)
 {
-  const tree *l1 = (const tree *)p1;
-  const tree *l2 = (const tree *)p2;
+  const tree *l1 = (const tree *) p1;
+  const tree *l2 = (const tree *) p2;
   return DECL_UID (*l1) - DECL_UID (*l2);
 }
 
@@ -131,8 +131,9 @@ pop_binding_level (void)
       /* Pop all the labels declared in the function.  */
       if (d_function_chain->labels)
 	{
-	  auto_vec<tree> labels;
-	  d_function_chain->labels->traverse<vec<tree> &, &pop_label> (labels);
+	  auto_vec <tree> labels;
+	  d_function_chain->labels->traverse <vec <tree> &,
+					      &pop_label> (labels);
 	  d_function_chain->labels->empty ();
 	  labels.qsort (cmp_labels);
 	  for (unsigned i = 0; i < labels.length (); ++i)
@@ -149,7 +150,7 @@ pop_binding_level (void)
       if (d_function_chain && d_function_chain->labels)
 	{
 	  language_function *f = d_function_chain;
-	  f->labels->traverse<binding_level *, &pop_binding_label> (level);
+	  f->labels->traverse <binding_level *, &pop_binding_label> (level);
 	}
 
       current_binding_level->blocks
@@ -292,7 +293,7 @@ public:
     tree block = pop_binding_level ();
     tree body = pop_stmt_list ();
 
-    if (! BLOCK_VARS (block))
+    if (!BLOCK_VARS (block))
       return body;
 
     tree bind = build3 (BIND_EXPR, void_type_node,
@@ -371,9 +372,9 @@ public:
     gcc_assert (ent != NULL);
 
     /* If the label hasn't been defined yet, defer checking.  */
-    if (! DECL_INITIAL (ent->label))
+    if (!DECL_INITIAL (ent->label))
       {
-	d_label_use_entry *fwdref = ggc_alloc<d_label_use_entry> ();
+	d_label_use_entry *fwdref = ggc_alloc <d_label_use_entry> ();
 	fwdref->level = current_binding_level;
 	fwdref->statement = from;
 	fwdref->next = ent->fwdrefs;
@@ -446,7 +447,7 @@ public:
     if (!d_function_chain->labels)
       {
 	d_function_chain->labels
-	  = hash_map<Statement *, d_label_entry>::create_ggc (13);
+	  = hash_map <Statement *, d_label_entry>::create_ggc (13);
       }
 
     d_label_entry *ent = d_function_chain->labels->get (s);
@@ -461,7 +462,7 @@ public:
 	DECL_MODE (decl) = VOIDmode;
 
 	/* Create new empty slot.  */
-	ent = ggc_cleared_alloc<d_label_entry> ();
+	ent = ggc_cleared_alloc <d_label_entry> ();
 	ent->statement = s;
 	ent->label = decl;
 
@@ -813,7 +814,7 @@ public:
 	/* Apparently the backend is supposed to sort and set the indexes
 	   on the case array, have to change them to be usable.  */
 	Type *satype = condtype->sarrayOf (s->cases->length);
-	vec<constructor_elt, va_gc> *elms = NULL;
+	vec <constructor_elt, va_gc> *elms = NULL;
 
 	s->cases->sort ();
 
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index b03019bdff5..ae281d55946 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -1683,12 +1683,12 @@ public:
   void visit (TypeAArray *t)
   {
     t->index->accept (this);
-    visit ((TypeNext *)t);
+    visit ((TypeNext *) t);
   }
 
   void visit (TypeFunction *t)
   {
-    visit ((TypeNext *)t);
+    visit ((TypeNext *) t);
   }
 
   void visit (TypeStruct *t)
-- 
2.25.1



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

* [committed] d: Use new isTypeXxxx helpers where possible.
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (4 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Update code formatting in a consistent style Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Use new isXxxxExp " Iain Buclaw
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces uses of casting to Type nodes with the newly
introduced isTypeXxxx functions.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-builtins.cc (d_eval_constant_expression): Use isTypeXxxx helpers
	instead of explicit casts.
	(d_build_builtins_module): Likewise.
	* d-codegen.cc (get_array_length): Likewise.
	(identity_compare_p): Likewise.
	(lower_struct_comparison): Likewise.
	(build_array_from_val): Likewise.
	(array_bounds_check): Likewise.
	(get_function_type): Likewise.
	(d_build_call): Likewise.
	* d-compiler.cc (Compiler::paintAsType): Likewise.
	* d-convert.cc (convert_expr): Likewise.
	(convert_for_assignment): Likewise.
	* d-lang.cc (d_classify_record): Likewise.
	(d_build_eh_runtime_type): Likewise.
	* decl.cc (DeclVisitor::visit): Likewise.
	* expr.cc (ExprVisitor::needs_postblit): Likewise.
	(ExprVisitor::needs_dtor): Likewise.
	(ExprVisitor::visit): Likewise.
	* imports.cc (ImportVisitor::visit): Likewise.
	* typeinfo.cc (get_typeinfo_kind): Likewise.
	(TypeInfoVisitor::visit): Likewise.
	(TypeDeclInfoVisitor::visit): Likewise.
	* types.cc (merge_aggregate_types): Likewise.
	(TypeVisitor::visit): Likewise.
---
 gcc/d/d-builtins.cc | 15 +++++-----
 gcc/d/d-codegen.cc  | 24 ++++++---------
 gcc/d/d-compiler.cc |  4 +--
 gcc/d/d-convert.cc  |  4 +--
 gcc/d/d-lang.cc     | 13 ++++-----
 gcc/d/decl.cc       | 16 ++++------
 gcc/d/expr.cc       | 71 ++++++++++++++++++---------------------------
 gcc/d/imports.cc    |  6 ++--
 gcc/d/typeinfo.cc   | 43 ++++++++++-----------------
 gcc/d/types.cc      |  6 ++--
 10 files changed, 82 insertions(+), 120 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index 91e3173e670..f1bdcb9fafd 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -388,7 +388,7 @@ d_eval_constant_expression (tree cst)
 	    }
 
 	  Expression *e = ArrayLiteralExp::create (Loc (), elements);
-	  e->type = ((TypeVector *) type)->basetype;
+	  e->type = type->isTypeVector ()->basetype;
 
 	  return VectorExp::create (Loc (), e, type);
 	}
@@ -517,8 +517,8 @@ d_build_builtins_module (Module *m)
   for (size_t i = 0; vec_safe_iterate (gcc_builtins_functions, i, &decl); ++i)
     {
       const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
-      TypeFunction *tf
-	= (TypeFunction *) build_frontend_type (TREE_TYPE (decl));
+      Type *t = build_frontend_type (TREE_TYPE (decl));
+      TypeFunction *tf = t ? t->isTypeFunction () : NULL;
 
       /* Cannot create built-in function type for DECL.  */
       if (!tf)
@@ -601,14 +601,13 @@ d_build_builtins_module (Module *m)
 
   /* Expose target-specific va_list type.  */
   Type *tvalist = target.va_listType (Loc (), NULL);
-  StructDeclaration *sd = (tvalist->ty == Tstruct)
-    ? ((TypeStruct *) tvalist)->sym : NULL;
-  if (sd == NULL || !sd->isAnonymous ())
+  TypeStruct *ts = tvalist->isTypeStruct ();
+  if (ts == NULL || !ts->sym->isAnonymous ())
     members->push (build_alias_declaration ("__builtin_va_list", tvalist));
   else
     {
-      sd->ident = Identifier::idPool ("__builtin_va_list");
-      members->push (sd);
+      ts->sym->ident = Identifier::idPool ("__builtin_va_list");
+      members->push (ts->sym);
     }
 
   /* Expose target-specific integer types to the builtins module.  */
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 83e757d5a38..1bf74e1f223 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -319,7 +319,7 @@ get_array_length (tree exp, Type *type)
   switch (tb->ty)
     {
     case Tsarray:
-      return size_int (((TypeSArray *) tb)->dim->toUInteger ());
+      return size_int (tb->isTypeSArray ()->dim->toUInteger ());
 
     case Tarray:
       return d_array_length (exp);
@@ -812,9 +812,8 @@ identity_compare_p (StructDeclaration *sd)
       Type *tb = vd->type->toBasetype ();
 
       /* Check inner data structures.  */
-      if (tb->ty == Tstruct)
+      if (TypeStruct *ts = tb->isTypeStruct ())
 	{
-	  TypeStruct *ts = (TypeStruct *) tb;
 	  if (!identity_compare_p (ts->sym))
 	    return false;
 	}
@@ -897,11 +896,10 @@ lower_struct_comparison (tree_code code, StructDeclaration *sd,
       tree t2ref = component_ref (t2, sfield);
       tree tcmp;
 
-      if (type->ty == Tstruct)
+      if (TypeStruct *ts = type->isTypeStruct ())
 	{
 	  /* Compare inner data structures.  */
-	  StructDeclaration *decl = ((TypeStruct *) type)->sym;
-	  tcmp = lower_struct_comparison (code, decl, t1ref, t2ref);
+	  tcmp = lower_struct_comparison (code, ts->sym, t1ref, t2ref);
 	}
       else if (type->ty != Tvector && type->isintegral ())
 	{
@@ -1680,15 +1678,13 @@ build_array_set (tree ptr, tree length, tree value)
 tree
 build_array_from_val (Type *type, tree val)
 {
-  gcc_assert (type->ty == Tsarray);
-
   tree etype = build_ctype (type->nextOf ());
 
   /* Initializing a multidimensional array.  */
   if (TREE_CODE (etype) == ARRAY_TYPE && TREE_TYPE (val) != etype)
     val = build_array_from_val (type->nextOf (), val);
 
-  size_t dims = ((TypeSArray *) type)->dim->toInteger ();
+  size_t dims = type->isTypeSArray ()->dim->toInteger ();
   vec<constructor_elt, va_gc> *elms = NULL;
   vec_safe_reserve (elms, dims);
 
@@ -1762,8 +1758,7 @@ array_bounds_check (void)
       fd = d_function_chain->function;
       if (fd && fd->type->ty == Tfunction)
 	{
-	  TypeFunction *tf = (TypeFunction *) fd->type;
-	  if (tf->trust == TRUSTsafe)
+	  if (fd->type->isTypeFunction ()->trust == TRUSTsafe)
 	    return true;
 	}
       return false;
@@ -1783,9 +1778,9 @@ get_function_type (Type *t)
   if (t->ty == Tpointer)
     t = t->nextOf ()->toBasetype ();
   if (t->ty == Tfunction)
-    tf = (TypeFunction *) t;
+    tf = t->isTypeFunction ();
   else if (t->ty == Tdelegate)
-    tf = (TypeFunction *) ((TypeDelegate *) t)->next;
+    tf = t->isTypeDelegate ()->next->isTypeFunction ();
   return tf;
 }
 
@@ -1916,8 +1911,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
 	  if (TREE_ADDRESSABLE (TREE_TYPE (targ)))
 	    {
 	      Type *t = arg->type->toBasetype ();
-	      gcc_assert (t->ty == Tstruct);
-	      StructDeclaration *sd = ((TypeStruct *) t)->sym;
+	      StructDeclaration *sd = t->isTypeStruct ()->sym;
 
 	      /* Nested structs also have ADDRESSABLE set, but if the type has
 		 neither a copy constructor nor a destructor available, then we
diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index a8adb983d06..75ca15737d9 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -111,7 +111,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
 	}
 
       /* Build vector type.  */
-      int nunits = ((TypeSArray *) expr->type)->dim->toUInteger ();
+      int nunits = expr->type->isTypeSArray ()->dim->toUInteger ();
       Type *telem = expr->type->nextOf ();
       tree vectype = build_vector_type (build_ctype (telem), nunits);
 
@@ -127,7 +127,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
     {
       /* Interpret value as a vector of the same size,
 	 then return the array literal.  */
-      int nunits = ((TypeSArray *) type)->dim->toUInteger ();
+      int nunits = type->isTypeSArray ()->dim->toUInteger ();
       Type *elem = type->nextOf ();
       tree vectype = build_vector_type (build_ctype (elem), nunits);
 
diff --git a/gcc/d/d-convert.cc b/gcc/d/d-convert.cc
index f93405ed956..80101f17b1d 100644
--- a/gcc/d/d-convert.cc
+++ b/gcc/d/d-convert.cc
@@ -467,7 +467,7 @@ convert_expr (tree exp, Type *etype, Type *totype)
 	}
       else if (tbtype->ty == Tarray)
 	{
-	  dinteger_t dim = ((TypeSArray *) ebtype)->dim->toInteger ();
+	  dinteger_t dim = ebtype->isTypeSArray ()->dim->toInteger ();
 	  dinteger_t esize = ebtype->nextOf ()->size ();
 	  dinteger_t tsize = tbtype->nextOf ()->size ();
 
@@ -616,7 +616,7 @@ convert_for_assignment (tree expr, Type *etype, Type *totype)
 
       if (same_type_p (telem, ebtype))
 	{
-	  TypeSArray *sa_type = (TypeSArray *) tbtype;
+	  TypeSArray *sa_type = tbtype->isTypeSArray ();
 	  uinteger_t count = sa_type->dim->toUInteger ();
 
 	  tree ctor = build_constructor (build_ctype (totype), NULL);
diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index badd67f5a8f..5266a6550dc 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1672,11 +1672,10 @@ static classify_record
 d_classify_record (tree type)
 {
   Type *t = TYPE_LANG_FRONTEND (type);
+  TypeClass *tc = t ? t->isTypeClass () : NULL;
 
-  if (t && t->ty == Tclass)
+  if (tc != NULL)
     {
-      TypeClass *tc = (TypeClass *) t;
-
       /* extern(C++) interfaces get emitted as classes.  */
       if (tc->sym->isInterfaceDeclaration ()
 	  && !tc->sym->isCPPinterface ())
@@ -1814,12 +1813,10 @@ static tree
 d_build_eh_runtime_type (tree type)
 {
   Type *t = TYPE_LANG_FRONTEND (type);
+  gcc_assert (t != NULL);
+  t = t->toBasetype ();
 
-  if (t != NULL)
-    t = t->toBasetype ();
-
-  gcc_assert (t != NULL && t->ty == Tclass);
-  ClassDeclaration *cd = ((TypeClass *) t)->sym;
+  ClassDeclaration *cd = t->isTypeClass ()->sym;
   tree decl;
 
   if (cd->isCPPclass ())
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 84aa42c139b..05868631eed 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -313,9 +313,9 @@ public:
     TemplateInstance *ti = NULL;
 
     if (tb->ty == Tstruct)
-      ti = ((TypeStruct *) tb)->sym->isInstantiated ();
+      ti = tb->isTypeStruct ()->sym->isInstantiated ();
     else if (tb->ty == Tclass)
-      ti = ((TypeClass *) tb)->sym->isInstantiated ();
+      ti = tb->isTypeClass ()->sym->isInstantiated ();
 
     /* Return type is instantiated from this template declaration, walk over
        all members of the instance.  */
@@ -620,7 +620,7 @@ public:
     if (have_typeinfo_p (Type::dtypeinfo))
       create_typeinfo (d->type, NULL);
 
-    TypeEnum *tc = (TypeEnum *) d->type;
+    TypeEnum *tc = d->type->isTypeEnum ();
     if (tc->sym->members && !d->type->isZeroInit ())
       {
 	/* Generate static initializer.  */
@@ -717,11 +717,8 @@ public:
 	  }
 	else
 	  {
-	    if (d->type->ty == Tstruct)
-	      {
-		StructDeclaration *sd = ((TypeStruct *) d->type)->sym;
-		DECL_INITIAL (decl) = layout_struct_initializer (sd);
-	      }
+	    if (TypeStruct *ts = d->type->isTypeStruct ())
+	      DECL_INITIAL (decl) = layout_struct_initializer (ts->sym);
 	    else
 	      {
 		Expression *e = d->type->defaultInitLiteral (d->loc);
@@ -813,9 +810,8 @@ public:
       return;
 
     /* Check if any errors occurred when running semantic.  */
-    if (d->type->ty == Tfunction)
+    if (TypeFunction *tf = d->type->isTypeFunction ())
       {
-	TypeFunction *tf = (TypeFunction *) d->type;
 	if (tf->next == NULL || tf->next->ty == Terror)
 	  return;
       }
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 1940480f9c4..9c80db15552 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -62,10 +62,9 @@ class ExprVisitor : public Visitor
   {
     t = t->baseElemOf ();
 
-    if (t->ty == Tstruct)
+    if (TypeStruct *ts = t->isTypeStruct ())
       {
-	StructDeclaration *sd = ((TypeStruct *) t)->sym;
-	if (sd->postblit)
+	if (ts->sym->postblit)
 	  return true;
       }
 
@@ -78,10 +77,9 @@ class ExprVisitor : public Visitor
   {
     t = t->baseElemOf ();
 
-    if (t->ty == Tstruct)
+    if (TypeStruct *ts = t->isTypeStruct ())
       {
-	StructDeclaration *sd = ((TypeStruct *) t)->sym;
-	if (sd->dtor)
+	if (ts->sym->dtor)
 	  return true;
       }
 
@@ -298,17 +296,16 @@ public:
 	      this->result_ = build_boolop (TRUTH_ORIF_EXPR, req, ieq);
 	  }
       }
-    else if (tb1->ty == Tstruct)
+    else if (TypeStruct *ts = tb1->isTypeStruct ())
       {
 	/* For struct objects, identity is defined as bits in operands being
 	   identical also.  Alignment holes in structs are ignored.  */
-	StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
 	tree t1 = build_expr (e->e1);
 	tree t2 = build_expr (e->e2);
 
 	gcc_assert (same_type_p (tb1, tb2));
 
-	this->result_ = build_struct_comparison (code, sd, t1, t2);
+	this->result_ = build_struct_comparison (code, ts->sym, t1, t2);
       }
     else
       {
@@ -345,7 +342,7 @@ public:
 	    Or when generating a NE expression:
 		e1.length != e2.length || memcmp(e1.ptr, e2.ptr, size) != 0;  */
 	if ((t1elem->isintegral () || t1elem->ty == Tvoid
-	     || (t1elem->ty == Tstruct && !((TypeStruct *)t1elem)->sym->xeq))
+	     || (t1elem->ty == Tstruct && !t1elem->isTypeStruct ()->sym->xeq))
 	    && t1elem->ty == t2elem->ty)
 	  {
 	    tree t1 = d_array_convert (e->e1);
@@ -367,7 +364,7 @@ public:
 	    /* Compare arrays using memcmp if possible, otherwise for structs,
 	       each field is compared inline.  */
 	    if (t1elem->ty != Tstruct
-		|| identity_compare_p (((TypeStruct *) t1elem)->sym))
+		|| identity_compare_p (t1elem->isTypeStruct ()->sym))
 	      {
 		tree size = size_mult_expr (t1len, size_int (t1elem->size ()));
 		tree tmemcmp = builtin_decl_explicit (BUILT_IN_MEMCMP);
@@ -377,7 +374,7 @@ public:
 	      }
 	    else
 	      {
-		StructDeclaration *sd = ((TypeStruct *) t1elem)->sym;
+		StructDeclaration *sd = t1elem->isTypeStruct ()->sym;
 
 		result = build_array_struct_comparison (code, sd, t1len,
 							t1ptr, t2ptr);
@@ -432,24 +429,22 @@ public:
 	    this->result_ = result;
 	  }
       }
-    else if (tb1->ty == Tstruct)
+    else if (TypeStruct *ts = tb1->isTypeStruct ())
       {
 	/* Equality for struct objects means the logical product of all
 	   equality results of the corresponding object fields.  */
-	StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
 	tree t1 = build_expr (e->e1);
 	tree t2 = build_expr (e->e2);
 
 	gcc_assert (same_type_p (tb1, tb2));
 
-	this->result_ = build_struct_comparison (code, sd, t1, t2);
+	this->result_ = build_struct_comparison (code, ts->sym, t1, t2);
       }
     else if (tb1->ty == Taarray && tb2->ty == Taarray)
       {
 	/* Use _aaEqual() for associative arrays.  */
-	TypeAArray *taa1 = (TypeAArray *) tb1;
 	tree result = build_libcall (LIBCALL_AAEQUAL, e->type, 3,
-				     build_typeinfo (e->loc, taa1),
+				     build_typeinfo (e->loc, tb1),
 				     build_expr (e->e1),
 				     build_expr (e->e2));
 
@@ -477,9 +472,7 @@ public:
   void visit (InExp *e)
   {
     Type *tb2 = e->e2->type->toBasetype ();
-    gcc_assert (tb2->ty == Taarray);
-
-    Type *tkey = ((TypeAArray *) tb2)->index->toBasetype ();
+    Type *tkey = tb2->isTypeAArray ()->index->toBasetype ();
     tree key = convert_expr (build_expr (e->e1), e->e1->type, tkey);
 
     /* Build a call to _aaInX().  */
@@ -1031,7 +1024,7 @@ public:
 	tree t1 = build_expr (e->e1);
 	tree t2 = convert_for_assignment (build_expr (e->e2),
 					  e->e2->type, e->e1->type);
-	StructDeclaration *sd = ((TypeStruct *) tb1)->sym;
+	StructDeclaration *sd = tb1->isTypeStruct ()->sym;
 
 	/* Look for struct = 0.  */
 	if (e->e2->op == TOKint64)
@@ -1193,7 +1186,7 @@ public:
     if (tb1->ty == Taarray)
       {
 	/* Get the key for the associative array.  */
-	Type *tkey = ((TypeAArray *) tb1)->index->toBasetype ();
+	Type *tkey = tb1->isTypeAArray ()->index->toBasetype ();
 	tree key = convert_expr (build_expr (e->e2), e->e2->type, tkey);
 	libcall_fn libcall;
 	tree tinfo, ptr;
@@ -1476,10 +1469,9 @@ public:
 	Type *telem = tb1->nextOf ()->baseElemOf ();
 	tree ti = null_pointer_node;
 
-	if (telem->ty == Tstruct)
+	if (TypeStruct *ts = telem->isTypeStruct ())
 	  {
 	    /* Might need to run destructor on array contents.  */
-	    TypeStruct *ts = (TypeStruct *) telem;
 	    if (ts->sym->dtor)
 	      ti = build_typeinfo (e->loc, tb1->nextOf ());
 	  }
@@ -1493,11 +1485,10 @@ public:
 	/* For pointers to a struct instance, if the struct has overloaded
 	   operator delete, then that operator is called.  */
 	t1 = build_address (t1);
-	Type *tnext = ((TypePointer *)tb1)->next->toBasetype ();
+	Type *tnext = tb1->isTypePointer ()->next->toBasetype ();
 
-	if (tnext->ty == Tstruct)
+	if (TypeStruct *ts = tnext->isTypeStruct ())
 	  {
-	    TypeStruct *ts = (TypeStruct *)tnext;
 	    if (ts->sym->dtor)
 	      {
 		tree ti = build_typeinfo (e->loc, tnext);
@@ -1527,7 +1518,7 @@ public:
     if (e->e1->type->toBasetype ()->ty == Taarray)
       {
 	Type *tb = e->e1->type->toBasetype ();
-	Type *tkey = ((TypeAArray *) tb)->index->toBasetype ();
+	Type *tkey = tb->isTypeAArray ()->index->toBasetype ();
 	tree index = convert_expr (build_expr (e->e2), e->e2->type, tkey);
 
 	this->result_ = build_libcall (LIBCALL_AADELX, Type::tbool, 3,
@@ -1623,7 +1614,7 @@ public:
        allocated in memory because its address is taken.  */
     if (tnext && tnext->ty == Tstruct)
       {
-	StructDeclaration *sd = ((TypeStruct *) tnext)->sym;
+	StructDeclaration *sd = tnext->isTypeStruct ()->sym;
 
 	for (size_t i = 0; i < sd->fields.length; i++)
 	  {
@@ -1998,7 +1989,7 @@ public:
 	      }
 	    else if (tb1->ty == Tpointer && tb1->nextOf ()->ty == Tstruct)
 	      {
-		StructDeclaration *sd = ((TypeStruct *) tb1->nextOf ())->sym;
+		StructDeclaration *sd = tb1->nextOf ()->isTypeStruct ()->sym;
 		if (sd->inv != NULL)
 		  {
 		    Expressions args;
@@ -2089,7 +2080,7 @@ public:
 	ci = indirect_ref (ptr_type_node, ci);
 
 	/* Add extra indirection for interfaces.  */
-	if (((TypeClass *) type)->sym->isInterfaceDeclaration ())
+	if (type->isTypeClass ()->sym->isInterfaceDeclaration ())
 	  ci = indirect_ref (ptr_type_node, ci);
 
 	this->result_ = build_nop (build_ctype (e->type), ci);
@@ -2288,9 +2279,8 @@ public:
       {
 	/* Allocating a new class.  */
 	tb = e->newtype->toBasetype ();
-	gcc_assert (tb->ty == Tclass);
 
-	ClassDeclaration *cd = ((TypeClass *) tb)->sym;
+	ClassDeclaration *cd = tb->isTypeClass ()->sym;
 	tree type = build_ctype (tb);
 	tree setup_exp = NULL_TREE;
 	tree new_call;
@@ -2368,10 +2358,9 @@ public:
       {
 	/* Allocating memory for a new struct.  */
 	Type *htype = e->newtype->toBasetype ();
-	gcc_assert (htype->ty == Tstruct);
 	gcc_assert (!e->onstack);
 
-	TypeStruct *stype = (TypeStruct *) htype;
+	TypeStruct *stype = htype->isTypeStruct ();
 	StructDeclaration *sd = stype->sym;
 	tree new_call;
 
@@ -2443,8 +2432,7 @@ public:
       {
 	/* Allocating memory for a new D array.  */
 	tb = e->newtype->toBasetype ();
-	gcc_assert (tb->ty == Tarray);
-	TypeDArray *tarray = (TypeDArray *) tb;
+	TypeDArray *tarray = tb->isTypeDArray ();
 
 	gcc_assert (!e->allocator);
 	gcc_assert (e->arguments && e->arguments->length >= 1);
@@ -2511,7 +2499,7 @@ public:
     else if (tb->ty == Tpointer)
       {
 	/* Allocating memory for a new pointer.  */
-	TypePointer *tpointer = (TypePointer *) tb;
+	TypePointer *tpointer = tb->isTypePointer ();
 
 	if (tpointer->next->size () == 0)
 	  {
@@ -2666,7 +2654,7 @@ public:
 
     /* Implicitly convert void[n] to ubyte[n].  */
     if (tb->ty == Tsarray && tb->nextOf ()->toBasetype ()->ty == Tvoid)
-      tb = Type::tuns8->sarrayOf (((TypeSArray *) tb)->dim->toUInteger ());
+      tb = Type::tuns8->sarrayOf (tb->isTypeSArray ()->dim->toUInteger ());
 
     gcc_assert (tb->ty == Tarray || tb->ty == Tsarray || tb->ty == Tpointer);
 
@@ -2781,10 +2769,9 @@ public:
   {
     /* Want the mutable type for typeinfo reference.  */
     Type *tb = e->type->toBasetype ()->mutableOf ();
-    gcc_assert (tb->ty == Taarray);
 
     /* Handle empty assoc array literals.  */
-    TypeAArray *ta = (TypeAArray *) tb;
+    TypeAArray *ta = tb->isTypeAArray ();
     if (e->keys->length == 0)
       {
 	this->result_ = build_constructor (build_ctype (ta), NULL);
@@ -3018,7 +3005,7 @@ public:
        interface offset to symbol.  */
     if (this->constp_)
       {
-	TypeClass *tc = (TypeClass *) e->type;
+	TypeClass *tc = e->type->toBasetype ()->isTypeClass ();
 	InterfaceDeclaration *to = tc->sym->isInterfaceDeclaration ();
 
 	if (to != NULL)
diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 2e3eb7408b7..e6e696ab325 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -131,11 +131,11 @@ public:
 	if (type != NULL)
 	  {
 	    if (type->ty == Tenum)
-	      dsym = ((TypeEnum *) type)->sym;
+	      dsym = type->isTypeEnum ()->sym;
 	    else if (type->ty == Tstruct)
-	      dsym = ((TypeStruct *) type)->sym;
+	      dsym = type->isTypeStruct ()->sym;
 	    else if (type->ty == Tclass)
-	      dsym = ((TypeClass *) type)->sym;
+	      dsym = type->isTypeClass ()->sym;
 	  }
       }
 
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 8249fa7c2e8..73443eaed50 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -140,7 +140,7 @@ get_typeinfo_kind (Type *type)
       return TK_TYPELIST_TYPE;
 
     case Tclass:
-      if (((TypeClass *) type)->sym->isInterfaceDeclaration ())
+      if (type->isTypeClass ()->sym->isInterfaceDeclaration ())
 	return TK_INTERFACE_TYPE;
       else
 	return TK_CLASSINFO_TYPE;
@@ -619,8 +619,7 @@ public:
 
   void visit (TypeInfoEnumDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tenum);
-    TypeEnum *ti = (TypeEnum *) d->tinfo;
+    TypeEnum *ti = d->tinfo->isTypeEnum ();
     EnumDeclaration *ed = ti->sym;
 
     /* The vtable for TypeInfo_Enum.  */
@@ -652,8 +651,7 @@ public:
 
   void visit (TypeInfoPointerDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tpointer);
-    TypePointer *ti = (TypePointer *) d->tinfo;
+    TypePointer *ti = d->tinfo->isTypePointer ();
 
     /* The vtable for TypeInfo_Pointer.  */
     this->layout_base (Type::typeinfopointer);
@@ -669,8 +667,7 @@ public:
 
   void visit (TypeInfoArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tarray);
-    TypeDArray *ti = (TypeDArray *) d->tinfo;
+    TypeDArray *ti = d->tinfo->isTypeDArray ();
 
     /* The vtable for TypeInfo_Array.  */
     this->layout_base (Type::typeinfoarray);
@@ -687,8 +684,7 @@ public:
 
   void visit (TypeInfoStaticArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tsarray);
-    TypeSArray *ti = (TypeSArray *) d->tinfo;
+    TypeSArray *ti = d->tinfo->isTypeSArray ();
 
     /* The vtable for TypeInfo_StaticArray.  */
     this->layout_base (Type::typeinfostaticarray);
@@ -708,8 +704,7 @@ public:
 
   void visit (TypeInfoAssociativeArrayDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Taarray);
-    TypeAArray *ti = (TypeAArray *) d->tinfo;
+    TypeAArray *ti = d->tinfo->isTypeAArray ();
 
     /* The vtable for TypeInfo_AssociativeArray.  */
     this->layout_base (Type::typeinfoassociativearray);
@@ -728,8 +723,7 @@ public:
 
   void visit (TypeInfoVectorDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tvector);
-    TypeVector *ti = (TypeVector *) d->tinfo;
+    TypeVector *ti = d->tinfo->isTypeVector ();
 
     /* The vtable for TypeInfo_Vector.  */
     this->layout_base (Type::typeinfovector);
@@ -746,8 +740,8 @@ public:
 
   void visit (TypeInfoFunctionDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tfunction && d->tinfo->deco != NULL);
-    TypeFunction *ti = (TypeFunction *) d->tinfo;
+    TypeFunction *ti = d->tinfo->isTypeFunction ();
+    gcc_assert (ti->deco != NULL);
 
     /* The vtable for TypeInfo_Function.  */
     this->layout_base (Type::typeinfofunction);
@@ -767,8 +761,8 @@ public:
 
   void visit (TypeInfoDelegateDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tdelegate && d->tinfo->deco != NULL);
-    TypeDelegate *ti = (TypeDelegate *) d->tinfo;
+    TypeDelegate *ti = d->tinfo->isTypeDelegate ();
+    gcc_assert (ti->deco != NULL);
 
     /* The vtable for TypeInfo_Delegate.  */
     this->layout_base (Type::typeinfodelegate);
@@ -801,8 +795,7 @@ public:
 
   void visit (TypeInfoClassDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tclass);
-    TypeClass *ti = (TypeClass *) d->tinfo;
+    TypeClass *ti = d->tinfo->isTypeClass ();
     ClassDeclaration *cd = ti->sym;
 
     /* The vtable for ClassInfo.  */
@@ -994,8 +987,7 @@ public:
 
   void visit (TypeInfoInterfaceDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tclass);
-    TypeClass *ti = (TypeClass *) d->tinfo;
+    TypeClass *ti = d->tinfo->isTypeClass ();
 
     if (!ti->sym->vclassinfo)
       ti->sym->vclassinfo = TypeInfoClassDeclaration::create (ti);
@@ -1028,8 +1020,7 @@ public:
 
   void visit (TypeInfoStructDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Tstruct);
-    TypeStruct *ti = (TypeStruct *) d->tinfo;
+    TypeStruct *ti = d->tinfo->isTypeStruct ();
     StructDeclaration *sd = ti->sym;
 
     /* The vtable for TypeInfo_Struct.  */
@@ -1128,8 +1119,7 @@ public:
 
   void visit (TypeInfoTupleDeclaration *d)
   {
-    gcc_assert (d->tinfo->ty == Ttuple);
-    TypeTuple *ti = (TypeTuple *) d->tinfo;
+    TypeTuple *ti = d->tinfo->isTypeTuple ();
 
     /* The vtable for TypeInfo_Tuple.  */
     this->layout_base (Type::typeinfotypelist);
@@ -1323,8 +1313,7 @@ public:
 
   void visit (TypeInfoClassDeclaration *tid)
   {
-    gcc_assert (tid->tinfo->ty == Tclass);
-    TypeClass *tc = (TypeClass *) tid->tinfo;
+    TypeClass *tc = tid->tinfo->isTypeClass ();
     tid->csym = get_classinfo_decl (tc->sym);
   }
 };
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index f3a1c473f7a..cb9a6dec7e5 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -498,9 +498,9 @@ merge_aggregate_types (Type *type, tree deco)
   AggregateDeclaration *sym;
 
   if (type->ty == Tstruct)
-    sym = ((TypeStruct *) type)->sym;
+    sym = type->isTypeStruct ()->sym;
   else if (type->ty == Tclass)
-    sym = ((TypeClass *) type)->sym;
+    sym = type->isTypeClass ()->sym;
   else
     gcc_unreachable ();
 
@@ -671,7 +671,7 @@ public:
 
   void visit (TypeVector *t)
   {
-    int nunits = ((TypeSArray *) t->basetype)->dim->toUInteger ();
+    int nunits = t->basetype->isTypeSArray ()->dim->toUInteger ();
     tree inner = build_ctype (t->elementType ());
 
     /* Same rationale as void static arrays.  */
-- 
2.25.1


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

* [committed] d: Use new isXxxxExp helpers where possible
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (5 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Use new isTypeXxxx helpers where possible Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Use toStringExp instead of explicit cast Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Use toTypeFunction " Iain Buclaw
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces uses of casting to Expression nodes with the newly
introduced isXxxxExp functions.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-attribs.cc (build_attributes): Use isXxxxExp helpers instead of
	explicit casts.
	* d-codegen.cc (d_build_call): Likewise.
	* d-compiler.cc (Compiler::paintAsType): Likewise.
	* decl.cc (ExprVisitor::visit): Likewise.
	(layout_class_initializer): Likewise.
	* expr.cc (ExprVisitor::lvalue_p): Likewise
	(ExprVisitor::visit): Likewise.
	* types.cc (layout_aggregate_members): Likewise.
---
 gcc/d/d-attribs.cc  |  6 ++---
 gcc/d/d-codegen.cc  |  2 +-
 gcc/d/d-compiler.cc |  4 +--
 gcc/d/decl.cc       | 11 ++++----
 gcc/d/expr.cc       | 62 +++++++++++++++++++++++++--------------------
 gcc/d/types.cc      |  2 +-
 6 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index b83db95e2a7..7e55b42fd03 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -268,7 +268,7 @@ build_attributes (Expressions *eattrs)
       /* Should now have a struct `Attribute("attrib", "value", ...)'
 	 initializer list.  */
       gcc_assert (attr->op == TOKstructliteral);
-      Expressions *elems = ((StructLiteralExp*) attr)->elements;
+      Expressions *elems = attr->isStructLiteralExp ()->elements;
       Expression *e0 = (*elems)[0];
 
       if (e0->op != TOKstring)
@@ -300,10 +300,10 @@ build_attributes (Expressions *eattrs)
       for (size_t j = 1; j < elems->length; j++)
 	{
 	  Expression *e = (*elems)[j];
+	  StringExp *s = e->isStringExp ();
 	  tree t;
-	  if (e->op == TOKstring && ((StringExp *) e)->sz == 1)
+	  if (s != NULL && s->sz == 1)
 	    {
-	      StringExp *s = (StringExp *) e;
 	      const char *string = (const char *)(s->len ? s->string : "");
 	      t = build_string (s->len, string);
 	    }
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 1bf74e1f223..d31638e2c1d 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1874,7 +1874,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
 
 	  if (arg->op == TOKcomma)
 	    {
-	      CommaExp *ce = (CommaExp *) arg;
+	      CommaExp *ce = arg->isCommaExp ();
 	      tree tce = build_expr (ce->e1);
 	      saved_args = compound_expr (saved_args, tce);
 	      (*arguments)[i] = ce->e2;
diff --git a/gcc/d/d-compiler.cc b/gcc/d/d-compiler.cc
index 75ca15737d9..41b3b53207a 100644
--- a/gcc/d/d-compiler.cc
+++ b/gcc/d/d-compiler.cc
@@ -88,7 +88,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
   else if (expr->op == TOKarrayliteral)
     {
       /* Build array as VECTOR_CST, assumes EXPR is constant.  */
-      Expressions *elements = ((ArrayLiteralExp *) expr)->elements;
+      Expressions *elements = expr->isArrayLiteralExp ()->elements;
       vec<constructor_elt, va_gc> *elms = NULL;
 
       vec_safe_reserve (elms, elements->length);
@@ -136,7 +136,7 @@ Compiler::paintAsType (UnionExp *, Expression *expr, Type *type)
       Expression *e = d_eval_constant_expression (cst);
       gcc_assert (e != NULL && e->op == TOKvector);
 
-      return ((VectorExp *) e)->e1;
+      return e->isVectorExp ()->e1;
     }
   else
     {
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index a6144f7c269..28d1d6d5f31 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -218,12 +218,11 @@ public:
     for (size_t i = 0; i < d->objects->length; i++)
       {
 	RootObject *o = (*d->objects)[i];
-	if ((o->dyncast () == DYNCAST_EXPRESSION)
-	    && ((Expression *) o)->op == TOKdsymbol)
+	if (o->dyncast () == DYNCAST_EXPRESSION)
 	  {
-	    Declaration *d = ((DsymbolExp *) o)->s->isDeclaration ();
-	    if (d)
-	      this->build_dsymbol (d);
+	    DsymbolExp *de = ((Expression *) o)->isDsymbolExp ();
+	    if (de != NULL && de->s->isDeclaration ())
+	      this->build_dsymbol (de->s);
 	  }
       }
   }
@@ -2239,7 +2238,7 @@ layout_class_initializer (ClassDeclaration *cd)
   Expression *e = ne->ctfeInterpret ();
   gcc_assert (e->op == TOKclassreference);
 
-  return build_class_instance ((ClassReferenceExp *) e);
+  return build_class_instance (e->isClassReferenceExp ());
 }
 
 tree
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 9c80db15552..06cd83a737d 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -90,9 +90,15 @@ class ExprVisitor : public Visitor
 
   bool lvalue_p (Expression *e)
   {
-    return ((e->op != TOKslice && e->isLvalue ())
-	    || (e->op == TOKslice && ((UnaExp *) e)->e1->isLvalue ())
-	    || (e->op == TOKcast && ((UnaExp *) e)->e1->isLvalue ()));
+    SliceExp *se = e->isSliceExp ();
+    if (se != NULL && se->e1->isLvalue ())
+      return true;
+
+    CastExp *ce = e->isCastExp ();
+    if (ce != NULL && ce->e1->isLvalue ())
+      return true;
+
+    return (e->op != TOKslice && e->isLvalue ());
   }
 
   /* Build an expression of code CODE, data type TYPE, and operands ARG0 and
@@ -174,7 +180,7 @@ class ExprVisitor : public Visitor
     Expression *e1b = e1;
     while (e1b->op == TOKcast)
       {
-	CastExp *ce = (CastExp *) e1b;
+	CastExp *ce = e1b->isCastExp ();
 	gcc_assert (same_type_p (ce->type, ce->to));
 	e1b = ce->e1;
       }
@@ -679,7 +685,7 @@ public:
 	  {
 	    if (ex->op == TOKcat)
 	      {
-		ex = ((CatExp *) ex)->e1;
+		ex = ex->isCatExp ()->e1;
 		ndims++;
 	      }
 	  }
@@ -696,7 +702,7 @@ public:
 	for (Expression *oe = ce->e2; oe != NULL;
 	     (ce->e1->op != TOKcat
 	      ? (oe = ce->e1)
-	      : (ce = (CatExp *)ce->e1, oe = ce->e2)))
+	      : (ce = ce->e1->isCatExp (), oe = ce->e2)))
 	  {
 	    tree arg = d_array_convert (etype, oe);
 	    tree index = size_int (dim);
@@ -790,7 +796,7 @@ public:
 	   Strip off casts just incase anyway.  */
 	while (e1b->op == TOKcast)
 	  {
-	    CastExp *ce = (CastExp *) e1b;
+	    CastExp *ce = e1b->isCastExp ();
 	    gcc_assert (same_type_p (ce->type, ce->to));
 	    e1b = ce->e1;
 	  }
@@ -883,7 +889,7 @@ public:
     if (e->e1->op == TOKarraylength)
       {
 	/* Assignment to an array's length property; resize the array.  */
-	ArrayLengthExp *ale = (ArrayLengthExp *) e->e1;
+	ArrayLengthExp *ale = e->e1->isArrayLengthExp ();
 	tree newlength = convert_expr (build_expr (e->e2), e->e2->type,
 				       Type::tsize_t);
 	tree ptr = build_address (build_expr (ale->e1));
@@ -904,7 +910,7 @@ public:
     /* Look for array[] = n;  */
     if (e->e1->op == TOKslice)
       {
-	SliceExp *se = (SliceExp *) e->e1;
+	SliceExp *se = e->e1->isSliceExp ();
 	Type *stype = se->e1->type->toBasetype ();
 	Type *etype = stype->nextOf ()->toBasetype ();
 
@@ -998,7 +1004,7 @@ public:
 	gcc_assert (e->op == TOKconstruct || e->op == TOKblit);
 	gcc_assert (e->e1->op == TOKvar);
 
-	Declaration *decl = ((VarExp *) e->e1)->var;
+	Declaration *decl = e->e1->isVarExp ()->var;
 	if (decl->storage_class & (STCout | STCref))
 	  {
 	    tree t2 = convert_for_assignment (build_expr (e->e2),
@@ -1443,7 +1449,7 @@ public:
 
 	if (e->e1->op == TOKvar)
 	  {
-	    VarDeclaration *v = ((VarExp *) e->e1)->var->isVarDeclaration ();
+	    VarDeclaration *v = e->e1->isVarExp ()->var->isVarDeclaration ();
 	    if (v && v->onstack)
 	      {
 		libcall = tb1->isClassHandle ()->isInterfaceDeclaration ()
@@ -1588,19 +1594,19 @@ public:
 
     if (e->e1->op == TOKadd)
       {
-	BinExp *be = (BinExp *) e->e1;
-	if (be->e1->op == TOKaddress
-	    && be->e2->isConst () && be->e2->type->isintegral ())
+	AddExp *ae = e->e1->isAddExp ();
+	if (ae->e1->op == TOKaddress
+	    && ae->e2->isConst () && ae->e2->type->isintegral ())
 	  {
-	    Expression *ae = ((AddrExp *) be->e1)->e1;
-	    tnext = ae->type->toBasetype ();
-	    result = build_expr (ae);
-	    offset = be->e2->toUInteger ();
+	    Expression *ex = ae->e1->isAddrExp ()->e1;
+	    tnext = ex->type->toBasetype ();
+	    result = build_expr (ex);
+	    offset = ae->e2->toUInteger ();
 	  }
       }
     else if (e->e1->op == TOKsymoff)
       {
-	SymOffExp *se = (SymOffExp *) e->e1;
+	SymOffExp *se = e->e1->isSymOffExp ();
 	if (!declaration_reference_p (se->var))
 	  {
 	    tnext = se->var->type->toBasetype ();
@@ -1652,7 +1658,7 @@ public:
        Taking the address of a struct literal is otherwise illegal.  */
     if (e->e1->op == TOKstructliteral)
       {
-	StructLiteralExp *sle = ((StructLiteralExp *) e->e1)->origin;
+	StructLiteralExp *sle = e->e1->isStructLiteralExp ()->origin;
 	gcc_assert (sle != NULL);
 
 	/* Build the reference symbol, the decl is built first as the
@@ -1690,21 +1696,21 @@ public:
     /* Calls to delegates can sometimes look like this.  */
     if (e1b->op == TOKcomma)
       {
-	e1b = ((CommaExp *) e1b)->e2;
+	e1b = e1b->isCommaExp ()->e2;
 	gcc_assert (e1b->op == TOKvar);
 
-	Declaration *var = ((VarExp *) e1b)->var;
+	Declaration *var = e1b->isVarExp ()->var;
 	gcc_assert (var->isFuncDeclaration () && !var->needThis ());
       }
 
     if (e1b->op == TOKdotvar && tb->ty != Tdelegate)
       {
-	DotVarExp *dve = (DotVarExp *) e1b;
+	DotVarExp *dve = e1b->isDotVarExp ();
 
 	/* Don't modify the static initializer for struct literals.  */
 	if (dve->e1->op == TOKstructliteral)
 	  {
-	    StructLiteralExp *sle = (StructLiteralExp *) dve->e1;
+	    StructLiteralExp *sle = dve->e1->isStructLiteralExp ();
 	    sle->useStaticInit = false;
 	  }
 
@@ -1767,7 +1773,7 @@ public:
 	    /* This gets the true function type, getting the function type
 	       from e1->type can sometimes be incorrect, such as when calling
 	       a 'ref' return function.  */
-	    tf = get_function_type (((DotVarExp *) e1b)->var->type);
+	    tf = get_function_type (e1b->isDotVarExp ()->var->type);
 	  }
 	else
 	  tf = get_function_type (tb);
@@ -1784,7 +1790,7 @@ public:
       }
     else if (e1b->op == TOKvar)
       {
-	FuncDeclaration *fd = ((VarExp *) e1b)->var->isFuncDeclaration ();
+	FuncDeclaration *fd = e1b->isVarExp ()->var->isFuncDeclaration ();
 	gcc_assert (fd != NULL);
 	tf = get_function_type (fd->type);
 
@@ -2145,7 +2151,7 @@ public:
   void visit (SymOffExp *e)
   {
     /* Build the address and offset of the symbol.  */
-    size_t soffset = ((SymOffExp *) e)->offset;
+    size_t soffset = e->isSymOffExp ()->offset;
     tree result = get_decl_tree (e->var);
     TREE_USED (result) = 1;
 
@@ -2956,7 +2962,7 @@ public:
     /* First handle array literal expressions.  */
     if (e->e1->op == TOKarrayliteral)
       {
-	ArrayLiteralExp *ale = ((ArrayLiteralExp *) e->e1);
+	ArrayLiteralExp *ale = e->e1->isArrayLiteralExp ();
 	vec<constructor_elt, va_gc> *elms = NULL;
 	bool constant_p = true;
 
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index cb9a6dec7e5..ba7e29a12e1 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -292,7 +292,7 @@ layout_aggregate_members (Dsymbols *members, tree context, bool inherited_p)
 		  gcc_assert (ro->dyncast () == DYNCAST_EXPRESSION);
 		  Expression *e = (Expression *) ro;
 		  gcc_assert (e->op == TOKdsymbol);
-		  DsymbolExp *se = (DsymbolExp *) e;
+		  DsymbolExp *se = e->isDsymbolExp ();
 
 		  tmembers.push (se->s);
 		}
-- 
2.25.1


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

* [committed] d: Use toStringExp instead of explicit cast
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (6 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Use new isXxxxExp " Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  2020-06-16 21:59 ` [committed] d: Use toTypeFunction " Iain Buclaw
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces uses of casting to StringExp with toStringExp.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-attribs.cc (build_attributes): Use toStringExp instead of cast.
	* toir.cc (IRVisitor::visit): Likewise.
---
 gcc/d/d-attribs.cc | 2 +-
 gcc/d/toir.cc      | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc
index 7e55b42fd03..79938075a7c 100644
--- a/gcc/d/d-attribs.cc
+++ b/gcc/d/d-attribs.cc
@@ -277,7 +277,7 @@ build_attributes (Expressions *eattrs)
 	  return error_mark_node;
 	}
 
-      StringExp *se = (StringExp*) e0;
+      StringExp *se = e0->toStringExp ();
       gcc_assert (se->sz == 1);
 
       /* Empty string attribute, just ignore it.  */
diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc
index d8a14efd667..130cbbafe00 100644
--- a/gcc/d/toir.cc
+++ b/gcc/d/toir.cc
@@ -1292,7 +1292,7 @@ public:
 
   void visit (GccAsmStatement *s)
   {
-    StringExp *insn = (StringExp *)s->insn;
+    StringExp *insn = s->insn->toStringExp ();
     tree outputs = NULL_TREE;
     tree inputs = NULL_TREE;
     tree clobbers = NULL_TREE;
@@ -1307,7 +1307,7 @@ public:
 	    const char *sname = name ? name->toChars () : NULL;
 	    tree id = name ? build_string (strlen (sname), sname) : NULL_TREE;
 
-	    StringExp *constr = (StringExp *)(*s->constraints)[i];
+	    StringExp *constr = (*s->constraints)[i]->toStringExp ();
 	    const char *cstring = (const char *)(constr->len
 						 ? constr->string : "");
 	    tree str = build_string (constr->len, cstring);
@@ -1333,7 +1333,7 @@ public:
       {
 	for (size_t i = 0; i < s->clobbers->length; i++)
 	  {
-	    StringExp *clobber = (StringExp *)(*s->clobbers)[i];
+	    StringExp *clobber = (*s->clobbers)[i]->toStringExp ();
 	    const char *cstring = (const char *)(clobber->len
 						 ? clobber->string : "");
 
-- 
2.25.1


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

* [committed] d: Use toTypeFunction instead of explicit cast
  2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
                   ` (7 preceding siblings ...)
  2020-06-16 21:59 ` [committed] d: Use toStringExp instead of explicit cast Iain Buclaw
@ 2020-06-16 21:59 ` Iain Buclaw
  8 siblings, 0 replies; 10+ messages in thread
From: Iain Buclaw @ 2020-06-16 21:59 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch replaces uses of casting to TypeFunction with toTypeFunction,
which takes care of asserting that `ty' is a `Tfunction'.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
master.

Regards
Iain


gcc/d/ChangeLog:

	* d-frontend.cc (eval_builtin): Use toTypeFunction instead of cast.
	* decl.cc (DeclVisitor::visit): Likewise.
	* toir.cc (IRVisitor::visit): Likewise.
	* typeinfo.cc (TypeInfoVisitor::visit): Likewise.
---
 gcc/d/d-frontend.cc |  2 +-
 gcc/d/decl.cc       | 28 ++++++++--------------------
 gcc/d/toir.cc       |  2 +-
 gcc/d/typeinfo.cc   |  3 +--
 4 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/gcc/d/d-frontend.cc b/gcc/d/d-frontend.cc
index 5415d471ef4..7434819d644 100644
--- a/gcc/d/d-frontend.cc
+++ b/gcc/d/d-frontend.cc
@@ -177,7 +177,7 @@ eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments)
   gcc_assert (fndecl_built_in_p (decl)
 	      || DECL_INTRINSIC_CODE (decl) != INTRINSIC_NONE);
 
-  TypeFunction *tf = (TypeFunction *) fd->type;
+  TypeFunction *tf = fd->type->toTypeFunction ();
   Expression *e = NULL;
   input_location = make_location_t (loc);
 
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 05868631eed..a6144f7c269 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -449,26 +449,14 @@ public:
 
 	    if (fd->leastAsSpecialized (fd2) || fd2->leastAsSpecialized (fd))
 	      {
-		TypeFunction *tf = (TypeFunction *) fd->type;
-		if (tf->ty == Tfunction)
-		  {
-		    error_at (make_location_t (fd->loc), "use of %qs",
-			      fd->toPrettyChars ());
-		    inform (make_location_t (fd2->loc), "is hidden by %qs",
-			    fd2->toPrettyChars ());
-		    inform (make_location_t (d->loc),
-			    "use %<alias %s = %s.%s;%> to introduce base class "
-			    "overload set", fd->toChars (),
-			    fd->parent->toChars (), fd->toChars ());
-		  }
-		else
-		  {
-		    error_at (make_location_t (fd->loc), "use of %qs",
-			      fd->toPrettyChars ());
-		    inform (make_location_t (fd2->loc), "is hidden by %qs",
-			      fd2->toPrettyChars ());
-		  }
-
+		error_at (make_location_t (fd->loc), "use of %qs",
+			  fd->toPrettyChars ());
+		inform (make_location_t (fd2->loc), "is hidden by %qs",
+			fd2->toPrettyChars ());
+		inform (make_location_t (d->loc),
+			"use %<alias %s = %s.%s;%> to introduce base class "
+			"overload set", fd->toChars (),
+			fd->parent->toChars (), fd->toChars ());
 		has_errors = true;
 		break;
 	      }
diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc
index 92d0ecdb0a0..d8a14efd667 100644
--- a/gcc/d/toir.cc
+++ b/gcc/d/toir.cc
@@ -1006,7 +1006,7 @@ public:
 	return;
       }
 
-    TypeFunction *tf = (TypeFunction *)this->func_->type;
+    TypeFunction *tf = this->func_->type->toTypeFunction ();
     Type *type = this->func_->tintro != NULL
       ? this->func_->tintro->nextOf () : tf->nextOf ();
 
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index 73443eaed50..f3051d3e122 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -1045,8 +1045,7 @@ public:
 
     if (sd->xhash)
       {
-	TypeFunction *tf = (TypeFunction *) sd->xhash->type;
-	gcc_assert (tf->ty == Tfunction);
+	TypeFunction *tf = sd->xhash->type->toTypeFunction ();
 	if (!tf->isnothrow || tf->trust == TRUSTsystem)
 	  {
 	    warning (sd->xhash->loc, "toHash() must be declared as "
-- 
2.25.1


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

end of thread, other threads:[~2020-06-16 22:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16 21:59 [committed] d: Consistently format quotations in comments Iain Buclaw
2020-06-16 21:59 ` [committed] d: Move generation of array bounds error to own function Iain Buclaw
2020-06-16 21:59 ` [committed] d: Remove dependency on front-end File type for json and deps file generation Iain Buclaw
2020-06-16 21:59 ` [committed] d: Remove dependency on front-end OutBuffer for diagnostic " Iain Buclaw
2020-06-16 21:59 ` [committed] d: Remove names of unused function parameters Iain Buclaw
2020-06-16 21:59 ` [committed] d: Update code formatting in a consistent style Iain Buclaw
2020-06-16 21:59 ` [committed] d: Use new isTypeXxxx helpers where possible Iain Buclaw
2020-06-16 21:59 ` [committed] d: Use new isXxxxExp " Iain Buclaw
2020-06-16 21:59 ` [committed] d: Use toStringExp instead of explicit cast Iain Buclaw
2020-06-16 21:59 ` [committed] d: Use toTypeFunction " 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).