This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH RFA: Initialize variable
- From: Ian Lance Taylor <iant at google dot com>
- To: Tobias SchlÃter <iant at google dot com>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 16 Jun 2009 20:41:17 -0700
- Subject: Re: PATCH RFA: Initialize variable
- References: <m3tz2fzzhz.fsf@google.com> <4A3804C2.7020706@physik.uni-muenchen.de>
"Tobias SchlÃter" <iant@google.com> writes:
> How about rewriting this as
> has_ts = (c->initializer->ts.cl
> && c->initializer->ts.cl->length_from_typespec);
>
> /* Remember the length of the first element ... */
> if (ctor)
> {
> gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
> gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
> first_len = ctor->expr->value.character.length;
> }
>
> for (; ctor; ctor = ctor->next)
> {
> if (ctor->expr->expr_type == EXPR_CONSTANT)
> ...
> Looks much cleaner to me, except for the fact that now ctor != NULL is
> established twice.
How about this patch? Bootstrapped and tested on
x86_64-unknown-linux-gnu.
Ian
2009-06-16 Ian Lance Taylor <iant@google.com>
* decl.c (build_struct): Rewrite loop over constructor elements.
Index: fortran/decl.c
===================================================================
--- fortran/decl.c (revision 148544)
+++ fortran/decl.c (working copy)
@@ -1435,28 +1435,26 @@ build_struct (const char *name, gfc_char
bool has_ts;
gfc_constructor *ctor = c->initializer->value.constructor;
- bool first = true;
- int first_len;
-
has_ts = (c->initializer->ts.cl
&& c->initializer->ts.cl->length_from_typespec);
- for (; ctor; ctor = ctor->next)
+ if (ctor)
{
- /* Remember the length of the first element for checking that
- all elements *in the constructor* have the same length. This
- need not be the length of the LHS! */
- if (first)
+ int first_len;
+
+ /* Remember the length of the first element for checking
+ that all elements *in the constructor* have the same
+ length. This need not be the length of the LHS! */
+ gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
+ gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
+ first_len = ctor->expr->value.character.length;
+
+ for (; ctor; ctor = ctor->next)
{
- gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
- gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
- first_len = ctor->expr->value.character.length;
- first = false;
+ if (ctor->expr->expr_type == EXPR_CONSTANT)
+ gfc_set_constant_character_len (len, ctor->expr,
+ has_ts ? -1 : first_len);
}
-
- if (ctor->expr->expr_type == EXPR_CONSTANT)
- gfc_set_constant_character_len (len, ctor->expr,
- has_ts ? -1 : first_len);
}
}
}