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]

[tree-ssa] Fix PR 13863, gcc.dg/uninit-D.c fails


The problem is that now with gimplifier, TREE_INITIAL is now null all the time so
the uninitialized warning was showing up even though the variable was initialized
against it self. This patch fixes that by using TREE_NO_WARNING on the decl and
checking TREE_NO_WARNING in uninitialized_vars_warning. It also removes the old
comment in uninitialized_vars_warning which no longer applies and the lang hook
which I had added to fix the other uninitialized warning bugs. It also a start
to fix PR 13127 which is about warning for non user defined variables.



Thanks, Andrew Pinski

ChangeLog:

	* c-common.c (c_decl_uninit_1): Remove.
	(c_decl_uninit): Remove.
	* c-common.h (c_decl_uninit): Remove prototype.
	* c-lang.c (LANG_HOOKS_DECL_UNINIT): Delete.
	* objc/objc-lang.c (LANG_HOOKS_DECL_UNINIT): Delete.
	* c-simplify.c (gimplify_decl_stmt): Set TREE_NO_WARNING
	on the decl where the initial is itself.
	* function.c (uninitialized_vars_warning): Remove old comment
	and check for DECL_INITIAL, replace with a check of TREE_NO_WARNING
	and do not call the langhook.
	* langhooks-def.h (LANG_HOOKS_DECL_UNINIT): Remove.
	(LANG_HOOKS_INITIALIZER): Remove usage of LANG_HOOKS_DECL_UNINIT.
	* langhooks.c (lhd_decl_uninit): Remove.
	* langhooks.h (lhd_decl_uninit): Remove prototype.

cp/ChangeLog:

cp-lang.c (LANG_HOOKS_DECL_UNINIT): Remove.

Patch:
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.344.2.59
diff -u -p -r1.344.2.59 c-common.c
--- c-common.c	30 Jan 2004 13:13:29 -0000	1.344.2.59
+++ c-common.c	6 Feb 2004 06:17:53 -0000
@@ -5986,37 +5986,6 @@ c_estimate_num_insns (tree decl)
   return num;
 }

-/* Used by c_decl_uninit to find where expressions like x = x + 1; */
-
-static tree
-c_decl_uninit_1 (tree *t, int *walk_sub_trees, void *x)
-{
- /* If x = EXP(&x)EXP, then do not warn about the use of x. */
- if (TREE_CODE (*t) == ADDR_EXPR && TREE_OPERAND (*t, 0) == x)
- {
- *walk_sub_trees = 0;
- return NULL_TREE;
- }
- if (*t == x)
- return *t;
- return NULL_TREE;
-}
-
-/* Find out if a variable is uninitialized based on DECL_INITIAL. */
-
-bool
-c_decl_uninit (tree t)
-{
- /* int x = x; is GCC extension to turn off this warning, only if warn_init_self is zero. */
- if (DECL_INITIAL (t) == t)
- return warn_init_self ? true : false;
-
- /* Walk the trees looking for the variable itself. */
- if (walk_tree_without_duplicates (&DECL_INITIAL (t), c_decl_uninit_1, t))
- return true;
- return false;
-}
-
/* Issue the error given by MSGID, indicating that it occurred before
TOKEN, which had the associated VALUE. */


Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.141.2.45
diff -u -p -r1.141.2.45 c-common.h
--- c-common.h	30 Jan 2004 13:13:30 -0000	1.141.2.45
+++ c-common.h	6 Feb 2004 06:17:53 -0000
@@ -1272,7 +1272,6 @@ extern void builtin_define_with_value (c
 extern void c_stddef_cpp_builtins (void);
 extern void fe_file_change (const struct line_map *);
 extern int c_estimate_num_insns (tree decl);
-extern bool c_decl_uninit (tree t);
 extern void c_parse_error (const char *, enum cpp_ttype, tree);

/* The following have been moved here from c-tree.h, since they're needed
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.94.2.17
diff -u -p -r1.94.2.17 c-lang.c
--- c-lang.c 25 Oct 2003 19:42:52 -0000 1.94.2.17
+++ c-lang.c 6 Feb 2004 06:17:53 -0000
@@ -90,8 +90,6 @@ enum c_language_kind c_language = clk_c;
#define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
#define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
-#undef LANG_HOOKS_DECL_UNINIT
-#define LANG_HOOKS_DECL_UNINIT c_decl_uninit


#undef LANG_HOOKS_RTL_EXPAND_STMT
#define LANG_HOOKS_RTL_EXPAND_STMT expand_stmt_toplev
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.91
diff -u -p -r1.1.4.91 c-simplify.c
--- c-simplify.c 4 Feb 2004 02:24:24 -0000 1.1.4.91
+++ c-simplify.c 6 Feb 2004 06:17:54 -0000
@@ -891,6 +891,11 @@ gimplify_decl_stmt (tree *stmt_p)
{
if (!TREE_STATIC (decl))
{
+ /* Do not warn about int x = x; as it is a GCC extension to turn
+ off this warning but only if warn_init_self is zero. */
+ if (init == decl && !warn_init_self)
+ TREE_NO_WARNING (decl) = 1;
+
DECL_INITIAL (decl) = NULL_TREE;
init = build (MODIFY_EXPR, void_type_node, decl, init);
if (stmts_are_full_exprs_p ())
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.374.2.38
diff -u -p -r1.374.2.38 function.c
--- function.c 30 Jan 2004 13:13:56 -0000 1.374.2.38
+++ function.c 6 Feb 2004 06:17:56 -0000
@@ -5678,14 +5678,8 @@ uninitialized_vars_warning (tree block)
&& ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
&& DECL_RTL_SET_P (decl)
&& GET_CODE (DECL_RTL (decl)) == REG
- /* Global optimizations can make it difficult to determine if a
- particular variable has been initialized. However, a VAR_DECL
- with a nonzero DECL_INITIAL had an initializer, so do not
- claim it is potentially uninitialized.
-
- When the DECL_INITIAL is NULL call the language hook to tell us
- if we want to warn. */
- && (DECL_INITIAL (decl) == NULL_TREE || lang_hooks.decl_uninit (decl))
+ /* Do not warn for decls which do not want the warning. */
+ && !TREE_NO_WARNING (decl)
&& regno_uninitialized (REGNO (DECL_RTL (decl))))
warning ("%J'%D' might be used uninitialized in this function",
decl, decl);
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.34.2.27
diff -u -p -r1.34.2.27 langhooks-def.h
--- langhooks-def.h 30 Jan 2004 13:14:05 -0000 1.34.2.27
+++ langhooks-def.h 6 Feb 2004 06:17:57 -0000
@@ -127,7 +127,6 @@ extern int lhd_gimplify_expr (tree *, tr
#define LANG_HOOKS_DECL_PRINTABLE_NAME lhd_decl_printable_name
#define LANG_HOOKS_GET_CALLEE_FNDECL lhd_return_null_tree
#define LANG_HOOKS_EXPR_SIZE lhd_expr_size
-#define LANG_HOOKS_DECL_UNINIT lhd_decl_uninit
#define LANG_HOOKS_TREE_SIZE lhd_tree_size


#define LANG_HOOKS_FUNCTION_INIT lhd_do_nothing_f
@@ -312,7 +311,6 @@ extern int lhd_tree_dump_type_quals (tre
LANG_HOOKS_GET_CALLEE_FNDECL, \
LANG_HOOKS_PRINT_ERROR_FUNCTION, \
LANG_HOOKS_EXPR_SIZE, \
- LANG_HOOKS_DECL_UNINIT, \
LANG_HOOKS_ATTRIBUTE_TABLE, \
LANG_HOOKS_COMMON_ATTRIBUTE_TABLE, \
LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE, \
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.31.2.21
diff -u -p -r1.31.2.21 langhooks.c
--- langhooks.c 30 Jan 2004 13:14:05 -0000 1.31.2.21
+++ langhooks.c 6 Feb 2004 06:17:57 -0000
@@ -472,14 +472,6 @@ lhd_expr_size (tree exp)
else
return size_in_bytes (TREE_TYPE (exp));
}
-/* lang_hooks.decl_uninit: Find out if a variable is uninitialized based
- on DECL_INITIAL. */
-
-bool
-lhd_decl_uninit (tree t ATTRIBUTE_UNUSED)
-{
- return false;
-}


/* lang_hooks.gimplify_expr re-writes *EXPR_P into GIMPLE form. */

Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.42.2.28
diff -u -p -r1.42.2.28 langhooks.h
--- langhooks.h	30 Jan 2004 13:14:05 -0000	1.42.2.28
+++ langhooks.h	6 Feb 2004 06:17:57 -0000
@@ -394,10 +394,6 @@ struct lang_hooks
      semantics in cases that it doesn't want to handle specially.  */
   tree (*expr_size) (tree);

- /* Called from uninitialized_vars_warning to find out if a variable is
- uninitialized based on DECL_INITIAL. */
- bool (*decl_uninit) (tree);
-
/* Pointers to machine-independent attribute tables, for front ends
using attribs.c. If one is NULL, it is ignored. Respectively, a
table of attributes specific to the language, a table of
Index: cp/cp-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-lang.c,v
retrieving revision 1.36.2.28
diff -u -p -r1.36.2.28 cp-lang.c
--- cp/cp-lang.c 13 Jan 2004 00:26:40 -0000 1.36.2.28
+++ cp/cp-lang.c 6 Feb 2004 06:18:04 -0000
@@ -112,8 +112,6 @@ static void cxx_initialize_diagnostics (
#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl
#undef LANG_HOOKS_WRITE_GLOBALS
#define LANG_HOOKS_WRITE_GLOBALS lhd_do_nothing
-#undef LANG_HOOKS_DECL_UNINIT
-#define LANG_HOOKS_DECL_UNINIT c_decl_uninit



#undef LANG_HOOKS_FUNCTION_INIT Index: objc/objc-lang.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v retrieving revision 1.24.2.13 diff -u -p -r1.24.2.13 objc-lang.c --- objc/objc-lang.c 25 Oct 2003 19:42:53 -0000 1.24.2.13 +++ objc/objc-lang.c 6 Feb 2004 06:18:04 -0000 @@ -81,8 +81,6 @@ enum c_language_kind c_language = clk_ob #define LANG_HOOKS_DECL_PRINTABLE_NAME objc_printable_name #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL c_warn_unused_global_decl -#undef LANG_HOOKS_DECL_UNINIT -#define LANG_HOOKS_DECL_UNINIT c_decl_uninit

 #undef LANG_HOOKS_FUNCTION_ENTER_NESTED
 #define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context


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