PATCH RFA: Initialize variable

Ian Lance Taylor iant@google.com
Tue Jun 16 20:37:00 GMT 2009


This is similar to the last patch I committed.

In some complicated cases the C++ compiler has a harder time determining
whether a variable is used uninitialized.  This is because the C++
compiler inserts a CLEANUP_EXPR which interferes with the gimplifier's
attempts to simplify conditional jumps.  This in turn means that the
conversion to SSA can leave some variable references appear to be
uninitialized, although a deeper inspection would show that they are
initialized.

One such case occurs in build_struct in fortran/decl.c.  The relevant
code is:

	  bool first = true;
	  int first_len;

	  has_ts = (c->initializer->ts.cl
		    && c->initializer->ts.cl->length_from_typespec);

	  for (; ctor; ctor = ctor->next)
	    {
	      /* 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)
		{
		  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);

Here first is true when entering the loop.  Therefore first_len is
always set by the time it reaches the use in the call to
gfc_set_constant_character_len.  The C frontend is able to figure this
out; the C++ frontend is not.

In slightly more complex cases we simply initialize the variable in
question.  I would like to do that here as well.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for mainline?

Ian


2009-06-16  Ian Lance Taylor  <iant@google.com>

	* decl.c (build_struct): Initialize first_len.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 448 bytes
Desc: Initialize variable
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090616/d4ebad43/attachment.bin>


More information about the Fortran mailing list