This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: missed uninitialised variable warning
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Michael Matz <matz at suse dot de>
- Cc: Andrew Pinski <pinskia at physics dot uc dot edu>, Gabriel Dos Reis <gdr at integrable-solutions dot net>, Alexandre Oliva <aoliva at redhat dot com>, Andrew Morton <akpm at osdl dot org>, <gcc at gcc dot gnu dot org>
- Date: Mon, 4 Aug 2003 09:56:32 -0400
- Subject: Re: missed uninitialised variable warning
On Monday, Aug 4, 2003, at 09:20 US/Eastern, Michael Matz wrote:
Hi,
On 4 Aug 2003, Gabriel Dos Reis wrote:
| Hmm, hard to fix ... I don't know, the patch below does it for the
easy
| 'x = x' case. But I immediately withdraw it, as I like this
feature ;-)
where were you when people argued with that? ;-)
I think I also argued for this feature. ;-)
The patch catches only one certain instance of the whole recursive
initialization problem. Namely it does not catch things like
"int i = g(i); int j = j + 1;" , i.e. any more complicated expression
than
the var itself.
Here is a patch which should warn about more complicated expressions.
If you want to limit gcc not warn about int i=i;, then add a condition
in contains_exp
for the case x==t and change the name of contains_exp.
Thanks,
Andrew Pinski
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1135
diff -u -p -r1.1135 Makefile.in
--- Makefile.in 1 Aug 2003 14:04:00 -0000 1.1135
+++ Makefile.in 4 Aug 2003 13:54:13 -0000
@@ -1525,7 +1525,7 @@ varasm.o : varasm.c $(CONFIG_H) $(SYSTEM
function.o : function.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H)
$(RTL_H) $(TREE_H) \
flags.h function.h $(EXPR_H) $(OPTABS_H) libfuncs.h $(REGS_H)
hard-reg-set.h \
insn-config.h $(RECOG_H) output.h toplev.h except.h $(HASHTAB_H)
$(GGC_H) \
- $(TM_P_H) langhooks.h gt-function.h
+ $(TM_P_H) tree-inline.h langhooks.h gt-function.h
stmt.o : stmt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H)
$(TREE_H) flags.h \
function.h insn-config.h hard-reg-set.h $(EXPR_H) libfuncs.h
except.h \
$(LOOP_H) $(RECOG_H) toplev.h output.h varray.h $(GGC_H) $(TM_P_H) \
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.449
diff -u -p -r1.449 function.c
--- function.c 25 Jul 2003 09:52:25 -0000 1.449
+++ function.c 4 Aug 2003 13:54:13 -0000
@@ -62,6 +62,7 @@ Software Foundation, 59 Temple Place - S
#include "tm_p.h"
#include "integrate.h"
#include "langhooks.h"
+#include "tree-inline.h"
#ifndef TRAMPOLINE_ALIGNMENT
#define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
@@ -5539,6 +5540,24 @@ pad_below (struct args_size *offset_ptr,
}
}
+/* Is the tree, t, the expression x. */
+static tree
+contains_exp_1 (tree *t , int *walk_sub_trees, void *x)
+{
+ if (*t == x)
+ return t;
+ return NULL_TREE;
+}
+
+/* Does the tree, t, contain the expression x. */
+static bool
+contains_exp (tree t, tree x)
+{
+ if (walk_tree_without_duplicates ( &t, contains_exp_1, x))
+ return true;
+ return false;
+}
+
/* Walk the tree of blocks describing the binding levels within a
function
and warn about uninitialized variables.
This is done after calling flow_analysis and before global_alloc
@@ -5566,7 +5585,8 @@ uninitialized_vars_warning (tree block)
We do not care about the actual value in DECL_INITIAL, so we do
not worry that it may be a dangling pointer. */
- && DECL_INITIAL (decl) == NULL_TREE
+ && (DECL_INITIAL (decl) == NULL_TREE || contains_exp (DECL_INITIAL
(decl), decl) )
&& regno_uninitialized (REGNO (DECL_RTL (decl))))
warning ("%H'%D' might be used uninitialized in this function",
&DECL_SOURCE_LOCATION (decl), decl);