diff mbox

Fix uninitialized error with BUILD_CONFIG=bootstrap-O1

Message ID orr5kfnp22.fsf@livre.localdomain
State New
Headers show

Commit Message

Alexandre Oliva June 10, 2010, 10:45 a.m. UTC
On both x86_64 and ia64, update_pointer_to in ada/gcc-interface/utils.c
fails to compile at -O1 with a warning that last may be used
uninitialized.

I suppose -O2 infers that new_ptr can't be NULL because it's
dereferenced before, so last will always be set before we exit the loop,
but at -O1 it doesn't.

This patch avoids the warning, but perhaps the loop should be turned
into a do/while loop to avoid the unnecessary test.

Regstrapped on x86_64-linux-gnu and ia64-linux-gnu.  Ok?

Comments

Eric Botcazou June 11, 2010, 4:49 p.m. UTC | #1
> I suppose -O2 infers that new_ptr can't be NULL because it's
> dereferenced before, so last will always be set before we exit the loop,
> but at -O1 it doesn't.
>
> This patch avoids the warning, but perhaps the loop should be turned
> into a do/while loop to avoid the unnecessary test.

The most correct version is 'last = NULL_TREE' but then the line overflows.
So I'd initialize 'last' to NULL_TREE in its declaration; OK with this change.
diff mbox

Patch

for  gcc/ada/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* gcc-interface/utils.c (update_pointer_to): Initialize last.

Index: gcc/ada/gcc-interface/utils.c
===================================================================
--- gcc/ada/gcc-interface/utils.c.orig	2010-06-09 07:10:50.000000000 -0300
+++ gcc/ada/gcc-interface/utils.c	2010-06-09 07:14:17.000000000 -0300
@@ -3497,7 +3497,7 @@  update_pointer_to (tree old_type, tree n
       /* Merge PTR in NEW_PTR.  */
       DECL_FIELD_CONTEXT (array_field) = new_ptr;
       DECL_FIELD_CONTEXT (bounds_field) = new_ptr;
-      for (t = new_ptr; t; last = t, t = TYPE_NEXT_VARIANT (t))
+      for (last = NULL, t = new_ptr; t; last = t, t = TYPE_NEXT_VARIANT (t))
 	TYPE_FIELDS (t) = TYPE_FIELDS (ptr);
 
       /* Chain PTR and its variants at the end.  */