This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[fortran] Set TREE_STATIC flag on static initializers
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: gcc-patches at gcc dot gnu dot org, rguenther at suse dot de
- Date: Sun, 5 Sep 2010 01:18:44 +0200
- Subject: [fortran] Set TREE_STATIC flag on static initializers
Hi,
fortran, unlike all other frontends, does not set TREE_STATIC flag on static
initializers. This prevents us from folding till the cfgexpand time. To be honest,
I am not quite sure why we insist on the flag (I guess we should assert that all statics
are initializerd with static initializer or ignore it), but this patch brings gfortran
into sync with others.
Bootstrapped/regtested x86_64-linux, OK?
Honza
* trans-expr.c (gfc_conv_initializer): Set TREE_STATIC on static ctors.
Index: fortran/trans-expr.c
===================================================================
--- fortran/trans-expr.c (revision 163862)
+++ fortran/trans-expr.c (working copy)
@@ -3992,19 +3992,23 @@ gfc_conv_initializer (gfc_expr * expr, g
gfc_init_se (&se, NULL);
gfc_conv_constant (&se, expr);
+ gcc_assert (TREE_CODE (se.expr) != CONSTRUCTOR);
return se.expr;
}
if (array && !procptr)
{
+ tree ctor;
/* Arrays need special handling. */
if (pointer)
- return gfc_build_null_descriptor (type);
+ ctor = gfc_build_null_descriptor (type);
/* Special case assigning an array to zero. */
else if (is_zero_initializer_p (expr))
- return build_constructor (type, NULL);
+ ctor = build_constructor (type, NULL);
else
- return gfc_conv_array_initializer (type, expr);
+ ctor = gfc_conv_array_initializer (type, expr);
+ TREE_STATIC (ctor) = 1;
+ return ctor;
}
else if (pointer || procptr)
{
@@ -4015,6 +4019,7 @@ gfc_conv_initializer (gfc_expr * expr, g
gfc_init_se (&se, NULL);
se.want_pointer = 1;
gfc_conv_expr (&se, expr);
+ gcc_assert (TREE_CODE (se.expr) != CONSTRUCTOR);
return se.expr;
}
}
@@ -4029,14 +4034,21 @@ gfc_conv_initializer (gfc_expr * expr, g
gfc_conv_structure (&se, gfc_class_null_initializer(ts), 1);
else
gfc_conv_structure (&se, expr, 1);
+ gcc_assert (TREE_CODE (se.expr) == CONSTRUCTOR);
+ TREE_STATIC (se.expr) = 1;
return se.expr;
case BT_CHARACTER:
- return gfc_conv_string_init (ts->u.cl->backend_decl,expr);
+ {
+ tree ctor = gfc_conv_string_init (ts->u.cl->backend_decl,expr);
+ TREE_STATIC (ctor) = 1;
+ return ctor;
+ }
default:
gfc_init_se (&se, NULL);
gfc_conv_constant (&se, expr);
+ gcc_assert (TREE_CODE (se.expr) != CONSTRUCTOR);
return se.expr;
}
}