[gfortran] Fix PR 15969

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat Jul 10 00:46:00 GMT 2004


We didn't handle the initialization of pointer elemnts in derived types.
Fixed thusly, with the help of Paul, Stevn and Andre Pinski :-)

Built and tested on i686-pc-linux. If anyone has a good idea for a
testcase I'm open to suggestions, in the tree dumps I can see that the
member is explicitly zeroed, but i don't see anything of this in the
assembly, most likely because our memory is initialized to zero anyway.

- Tobi

2004-07-10  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>
	Paul Brook <paul@codesourcery.com>
	Steven Bosscher <stevenb@suse.de>
	Andrew Pinski <pinskia@physics.uc.edu>

	PR fortran/15969
	* trans-expr (gfc_conv_structure): Handle initialization
	of pointer components.

Index: trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.12
diff -u -p -r1.12 trans-expr.c
--- trans-expr.c        29 Jun 2004 22:01:35 -0000      1.12
+++ trans-expr.c        10 Jul 2004 00:34:08 -0000
@@ -1381,7 +1381,7 @@ gfc_conv_structure (gfc_se * se, gfc_exp
   tree type;
   tree arraytype;

-  assert (expr->expr_type == EXPR_STRUCTURE);
+  assert (expr->expr_type == EXPR_STRUCTURE || expr->expr_type ==
EXPR_NULL);
   type = gfc_typenode_for_spec (&expr->ts);
   head = build1 (CONSTRUCTOR, type, NULL_TREE);
   tail = NULL_TREE;
@@ -1397,15 +1397,25 @@ gfc_conv_structure (gfc_se * se, gfc_exp
       /* Evaluate the expression for this component.  */
       if (init)
        {
-         if (cm->dimension)
+         if (!cm->pointer)
            {
-             arraytype = TREE_TYPE (cm->backend_decl);
-             cse.expr = gfc_conv_array_initializer (arraytype, c->expr);
+             /* Initializing a non-pointer element.  */
+             if (cm->dimension)
+               {
+                 arraytype = TREE_TYPE (cm->backend_decl);
+                 cse.expr = gfc_conv_array_initializer (arraytype,
c->expr);
+               }
+             else if (cm->ts.type == BT_DERIVED)
+               gfc_conv_structure (&cse, c->expr, 1);
+             else
+               gfc_conv_expr (&cse, c->expr);
+
            }
-         else if (cm->ts.type == BT_DERIVED)
-           gfc_conv_structure (&cse, c->expr, 1);
          else
-           gfc_conv_expr (&cse, c->expr);
+           /* Pointer components may only be initialized to
+              NULL. This should have been enforced by the frontend.  */
+           cse.expr = fold_convert (TREE_TYPE (cm->backend_decl),
+                                    null_pointer_node);
        }
       else
        {



More information about the Fortran mailing list