This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[vta, trunk?] avoid uninitialized variable warnings building with -O3


This fixes some warnings I got in the VTA branch building on x86_64,
i686, ppc64 and ia64 with -O1, -O2 and -O3 in BOOT_CFLAGS.  I don't
remember which was triggered where, but this doesn't matter.

Initialization for binary_loc shouldn't be necessary, this appears to
be a defficiency of the optimizer, that doesn't realize that the POPs
at the end will never be executed unless we ever PUSH something, at
which point binary_loc will have been initialized.  Can't quite blame
the optimizer for not figuring that out :-)

The initialization of ebitmap fields was deemed necessary after SRA
made separate variables out of them in a scenario in which a lot of
ebitmap operations got inlined.  It was another scenario in which an
initialization would necessarily take place before any actual
reference to those fields, but the optimizer couldn't figure it out.

Turning the conditional on ARRAY_TYPE into an assertion avoids falling
off the if-then-else-if-... chain without initializing the members of
wr, which would in turn trigger warnings because the compiler couldn't
possibly know that all cases are covered.

Installing in the branch.  Ok for trunk?

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

	* c-parser.c (c_parser_binary_expression): Initialize binary_loc.
	* ebitmap.h (ebitmap_iter_init): Initialize all fields.
	* ipa-struct-reorg.c (gen_struct_type): Replace known-true
	test with assertion.

Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c.orig	2008-10-10 09:31:06.000000000 -0300
+++ gcc/c-parser.c	2008-10-15 05:06:28.000000000 -0300
@@ -4583,7 +4583,7 @@ c_parser_binary_expression (c_parser *pa
   } stack[NUM_PRECS];
   int sp;
   /* Location of the binary operator.  */
-  location_t binary_loc;
+  location_t binary_loc = input_location;
 #define POP								      \
   do {									      \
     switch (stack[sp].op)						      \
Index: gcc/ebitmap.h
===================================================================
--- gcc/ebitmap.h.orig	2008-07-29 18:38:15.000000000 -0300
+++ gcc/ebitmap.h	2008-10-15 05:17:56.000000000 -0300
@@ -1,5 +1,5 @@
 /* Sparse array based bitmaps.
-   Copyright (C) 2007 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -95,7 +95,13 @@ ebitmap_iter_init (ebitmap_iterator *i, 
 		     min / EBITMAP_ELT_BITS);
   i->size = bmp->numwords;
   if (i->size == 0)
-    return;
+    {
+      i->ptr = NULL;
+      i->eltnum = 0;
+      i->bit_num = 0;
+      i->word = 0;
+      return;
+    }
   i->ptr = bmp->elts;
   i->bit_num = min;
   i->eltnum = 0;
Index: gcc/ipa-struct-reorg.c
===================================================================
--- gcc/ipa-struct-reorg.c.orig	2008-10-15 05:12:39.000000000 -0300
+++ gcc/ipa-struct-reorg.c	2008-10-15 05:12:57.000000000 -0300
@@ -1865,8 +1865,9 @@ gen_struct_type (tree decl, tree new_str
 	  wr.wrap = 0;
 	  wr.domain = NULL_TREE;
 	}
-      else if (TREE_CODE (type_orig) == ARRAY_TYPE)
+      else
 	{
+	  gcc_assert (TREE_CODE (type_orig) == ARRAY_TYPE);
 	  wr.wrap = 1;
 	  wr.domain = TYPE_DOMAIN (type_orig);
 	}
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member       ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}

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