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]

[patch, fortran] [4.5/4.4 Regression] data statement with nested type constructors


Hi folks,

Attempting to backport the simple patch from mainline to 4.4 revealed a problem downstream reulting in a segfault. The issue is that the error I am giving on the invalid code was leaving the se->expr uninitialized and the middle-end does not handle that situation. This patch resolves the issue.

Not exactly obvious, but simple enough. Regression tested on 4.4 and 4.5. Test cases as in the original patch.

OK for 4.4 and forward port to 4.5?

Jerry

2009-11-21 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/41807
	* trans-const.c (gfc_conv_const): Fix typo in comment. Replace assert
	with error message if not constant. Set se->expr.
	* resolve.c (next_data_value): Delete check for constant.

This is the relevant portion of the patch against current trunk
Index: trans-const.c
===================================================================
--- trans-const.c	(revision 154421)
+++ trans-const.c	(working copy)
@@ -356,6 +356,7 @@
   if (expr->expr_type != EXPR_CONSTANT)
     {
       gfc_error ("non-constant initialization expression at %L", &expr->where);
+      se->expr = gfc_conv_constant_to_tree (gfc_int_expr (0));
       return;
     }

Full patch for 4.4:

Index: trans-const.c
===================================================================
--- trans-const.c	(revision 154660)
+++ trans-const.c	(working copy)
@@ -336,7 +336,7 @@ void
 gfc_conv_constant (gfc_se * se, gfc_expr * expr)
 {
   /* We may be receiving an expression for C_NULL_PTR or C_NULL_FUNPTR.  If
-     so, they expr_type will not yet be an EXPR_CONSTANT.  We need to make
+     so, the expr_type will not yet be an EXPR_CONSTANT.  We need to make
      it so here.  */
   if (expr->ts.type == BT_DERIVED && expr->ts.derived
       && expr->ts.derived->attr.is_iso_c)
@@ -349,7 +349,12 @@ gfc_conv_constant (gfc_se * se, gfc_expr * expr)
         }
     }

-  gcc_assert (expr->expr_type == EXPR_CONSTANT);
+  if (expr->expr_type != EXPR_CONSTANT)
+    {
+      gfc_error ("non-constant initialization expression at %L", &expr->where);
+      se->expr = gfc_conv_constant_to_tree (gfc_int_expr (0));
+      return;
+    }

   if (se->ss != NULL)
     {
Index: resolve.c
===================================================================
--- resolve.c	(revision 154660)
+++ resolve.c	(working copy)
@@ -9447,10 +9447,6 @@ next_data_value (void)
 {
   while (mpz_cmp_ui (values.left, 0) == 0)
     {
-      if (!gfc_is_constant_expr (values.vnode->expr))
-	gfc_error ("non-constant DATA value at %L",
-		   &values.vnode->expr->where);
-
       if (values.vnode->next == NULL)
 	return FAILURE;




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