This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch to warn_uninit
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 02 Apr 2005 09:02:57 -0800
- Subject: patch to warn_uninit
Another patch needed to fix --enable-mapped-location regressions.
In this case the locus may be set to an EXPR_LOCUS (in
execute_early_warn_uninitialize), which may be addree of an
expression whose actual location is UNKNOWN_LOCATION.
There is a slight awkwardness in two tests: We should use
either NULL or UNKNOWN_LOCATION but not allow either. But
I think that's a future cleanup.
Another awkwardness is that we're passing around an address
into the interior of an expression node. This is probably
not a good idea when dealing with garbage collectors.
An alternative is to pass the actual tree node in the calls to
walk_node, rather than the locus - something like the attached
tree-ssa.alt-patch. I haven't verified that this alternative
patch works (except that it compiles), but I can if that is
deemed nicer.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2005-04-02 Per Bothner <per@bothner.com>
* tree-ssa.c (warn_uninit): Also check if locus is UNKNOWN_LOCATION.
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.83
diff -u -p -r2.83 tree-ssa.c
--- tree-ssa.c 30 Mar 2005 22:10:47 -0000 2.83
+++ tree-ssa.c 2 Apr 2005 16:24:00 -0000
@@ -1360,7 +1360,11 @@ warn_uninit (tree t, const char *msgid,
if (TREE_NO_WARNING (var))
return;
+#ifdef USE_MAPPED_LOCATION
+ if (locus == NULL || *locus == UNKNOWN_LOCATION)
+#else
if (!locus)
+#endif
locus = &DECL_SOURCE_LOCATION (var);
warning (msgid, locus, var);
TREE_NO_WARNING (var) = 1;
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa.c,v
retrieving revision 2.83
diff -u -p -r2.83 tree-ssa.c
--- tree-ssa.c 30 Mar 2005 22:10:47 -0000 2.83
+++ tree-ssa.c 2 Apr 2005 17:00:51 -0000
@@ -1337,10 +1337,12 @@ struct tree_opt_pass pass_redundant_phi
warning text is in MSGID and LOCUS may contain a location or be null. */
static void
-warn_uninit (tree t, const char *msgid, location_t *locus)
+warn_uninit (tree t, const char *msgid, void *data)
{
tree var = SSA_NAME_VAR (t);
tree def = SSA_NAME_DEF_STMT (t);
+ tree context = (tree) data;
+ location_t * locus;
/* Default uses (indicated by an empty definition statement),
are uninitialized. */
@@ -1360,8 +1362,9 @@ warn_uninit (tree t, const char *msgid,
if (TREE_NO_WARNING (var))
return;
- if (!locus)
- locus = &DECL_SOURCE_LOCATION (var);
+ locus = (context != NULL && EXPR_HAS_LOCATION (context)
+ ? EXPR_LOCUS (context)
+ : &DECL_SOURCE_LOCATION (var));
warning (msgid, locus, var);
TREE_NO_WARNING (var) = 1;
}
@@ -1372,13 +1375,12 @@ warn_uninit (tree t, const char *msgid,
static tree
warn_uninitialized_var (tree *tp, int *walk_subtrees, void *data)
{
- location_t *locus = data;
tree t = *tp;
/* We only do data flow with SSA_NAMEs, so that's all we can warn about. */
if (TREE_CODE (t) == SSA_NAME)
{
- warn_uninit (t, "%H%qD is used uninitialized in this function", locus);
+ warn_uninit (t, "%H%qD is used uninitialized in this function", data);
*walk_subtrees = 0;
}
else if (IS_TYPE_OR_DECL_P (t))
@@ -1416,8 +1418,11 @@ execute_early_warn_uninitialized (void)
FOR_EACH_BB (bb)
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
- walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var,
- EXPR_LOCUS (bsi_stmt (bsi)), NULL);
+ {
+ tree context = bsi_stmt (bsi);
+ walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var,
+ context, NULL);
+ }
}
static void