This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran, committing] Cleanup gfc_finish_decl



gfc_finish_decl() wasn't ever called with a second argument different from NULL_TREE. This patch, which I will commit under the obvious rule once testing finishes, removes that second argument, and removes all the code that depends on its value being non-NULL, leaving us with a much simpler function. While I was at it, I also replaced the calls to gfc_fatal_error (which are for user errors where the compiler can't continue) with calls to gcc_assert (which is the intended means for internal consistency checks).


Built and tested on i386-darwin.

- Tobi
	* trans-decl.c (gfc_finish_decl): Remove unused second argument
	'init'.  Simplify code accordingly.  Remove calls to
	gfc_fatal_error in favor of gcc_assert.
	(create_function_arglist): Remove second argument from calls to
	gfc_finish-decl.
	(gfc_trans_dummy_character): Likewise.

Index: trans-decl.c
===================================================================
--- trans-decl.c	(revision 123911)
+++ trans-decl.c	(working copy)
@@ -406,59 +406,38 @@ gfc_finish_cray_pointee (tree decl, gfc_
 }
 
 
-/* Finish processing of a declaration and install its initial value.  */
+/* Finish processing of a declaration without an initial value.  */
 
 static void
-gfc_finish_decl (tree decl, tree init)
+gfc_finish_decl (tree decl)
 {
-  if (TREE_CODE (decl) == PARM_DECL)
-    gcc_assert (init == NULL_TREE);
-  /* Remember that PARM_DECL doesn't have a DECL_INITIAL field per se
-     -- it overlaps DECL_ARG_TYPE.  */
-  else if (init == NULL_TREE)
-    gcc_assert (DECL_INITIAL (decl) == NULL_TREE);
-  else
-    gcc_assert (DECL_INITIAL (decl) == error_mark_node);
-
-  if (init != NULL_TREE)
-    {
-      if (TREE_CODE (decl) != TYPE_DECL)
-	DECL_INITIAL (decl) = init;
-      else
-	{
-	  /* typedef foo = bar; store the type of bar as the type of foo.  */
-	  TREE_TYPE (decl) = TREE_TYPE (init);
-	  DECL_INITIAL (decl) = init = 0;
-	}
-    }
-
-  if (TREE_CODE (decl) == VAR_DECL)
-    {
-      if (DECL_SIZE (decl) == NULL_TREE
-	  && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
-	layout_decl (decl, 0);
-
-      /* A static variable with an incomplete type is an error if it is
-         initialized. Also if it is not file scope. Otherwise, let it
-         through, but if it is not `extern' then it may cause an error
-         message later.  */
-      /* An automatic variable with an incomplete type is an error.  */
-      if (DECL_SIZE (decl) == NULL_TREE
-          && (TREE_STATIC (decl) ? (DECL_INITIAL (decl) != 0
-				    || DECL_CONTEXT (decl) != 0)
-                                 : !DECL_EXTERNAL (decl)))
-	{
-	  gfc_fatal_error ("storage size not known");
-	}
+  gcc_assert (TREE_CODE (decl) == PARM_DECL
+	      || DECL_INITIAL (decl) == NULL_TREE);
 
-      if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
-	  && (DECL_SIZE (decl) != 0)
-	  && (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST))
-	{
-	  gfc_fatal_error ("storage size not constant");
-	}
-    }
+  if (TREE_CODE (decl) != VAR_DECL)
+    return;
 
+  if (DECL_SIZE (decl) == NULL_TREE
+      && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
+    layout_decl (decl, 0);
+
+  /* A few consistency checks.  */
+  /* A static variable with an incomplete type is an error if it is
+     initialized. Also if it is not file scope. Otherwise, let it
+     through, but if it is not `extern' then it may cause an error
+     message later.  */
+  /* An automatic variable with an incomplete type is an error.  */
+
+  /* We should know the storage size.  */
+  gcc_assert (DECL_SIZE (decl) != NULL_TREE
+	      || (TREE_STATIC (decl) 
+		  ? (!DECL_INITIAL (decl) || !DECL_CONTEXT (decl))
+		  : DECL_EXTERNAL (decl)));
+
+  /* The storage size should be constant.  */
+  gcc_assert ((!DECL_EXTERNAL (decl) && !TREE_STATIC (decl))
+	      || !DECL_SIZE (decl)
+	      || TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST);
 }
 
 
@@ -1324,7 +1303,7 @@ create_function_arglist (gfc_symbol * sy
       DECL_CONTEXT (parm) = fndecl;
       DECL_ARG_TYPE (parm) = type;
       TREE_READONLY (parm) = 1;
-      gfc_finish_decl (parm, NULL_TREE);
+      gfc_finish_decl (parm);
       DECL_ARTIFICIAL (parm) = 1;
 
       arglist = chainon (arglist, parm);
@@ -1354,7 +1333,7 @@ create_function_arglist (gfc_symbol * sy
 	  DECL_ARG_TYPE (length) = len_type;
 	  TREE_READONLY (length) = 1;
 	  DECL_ARTIFICIAL (length) = 1;
-	  gfc_finish_decl (length, NULL_TREE);
+	  gfc_finish_decl (length);
 	  if (sym->ts.cl->backend_decl == NULL
 	      || sym->ts.cl->backend_decl == length)
 	    {
@@ -1389,7 +1368,7 @@ create_function_arglist (gfc_symbol * sy
       DECL_ARG_TYPE (parm) = TREE_VALUE (typelist);
       TREE_READONLY (parm) = 1;
       DECL_ARTIFICIAL (parm) = 1;
-      gfc_finish_decl (parm, NULL_TREE);
+      gfc_finish_decl (parm);
 
       arglist = chainon (arglist, parm);
       typelist = TREE_CHAIN (typelist);
@@ -1432,7 +1411,7 @@ create_function_arglist (gfc_symbol * sy
 	  DECL_ARTIFICIAL (length) = 1;
 	  DECL_ARG_TYPE (length) = len_type;
 	  TREE_READONLY (length) = 1;
-	  gfc_finish_decl (length, NULL_TREE);
+	  gfc_finish_decl (length);
 
 	  /* TODO: Check string lengths when -fbounds-check.  */
 
@@ -1501,7 +1480,7 @@ create_function_arglist (gfc_symbol * sy
       /* All implementation args are read-only.  */
       TREE_READONLY (parm) = 1;
 
-      gfc_finish_decl (parm, NULL_TREE);
+      gfc_finish_decl (parm);
 
       f->sym->backend_decl = parm;
 
@@ -2417,7 +2396,7 @@ gfc_trans_dummy_character (gfc_symbol *s
 {
   stmtblock_t body;
 
-  gfc_finish_decl (cl->backend_decl, NULL_TREE);
+  gfc_finish_decl (cl->backend_decl);
 
   gfc_start_block (&body);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]