This is the mail archive of the 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 RFA: Initialize variable

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

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->
		    && c->initializer->>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?


2009-06-16  Ian Lance Taylor  <>

	* decl.c (build_struct): Initialize first_len.

Index: fortran/decl.c
--- fortran/decl.c	(revision 148544)
+++ fortran/decl.c	(working copy)
@@ -1436,7 +1436,7 @@ build_struct (const char *name, gfc_char
 	  gfc_constructor *ctor = c->initializer->value.constructor;
 	  bool first = true;
-	  int first_len;
+	  int first_len = 0;
 	  has_ts = (c->initializer->
 		    && c->initializer->>length_from_typespec);

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