aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-uninit.c
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@arm.com>2014-05-08 01:20:17 +0000
committerJoey Ye <jye2@gcc.gnu.org>2014-05-08 01:20:17 +0000
commite1ec47c453e0d7cb4e62d1d1f6c0efb43cc0bfb5 (patch)
tree9c87b46e418e3508e38a27583c76e3829a43b781 /gcc/tree-ssa-uninit.c
parent10e08855d74dc3f35bb295ac2747f48dd037bee6 (diff)
downloadgcc-e1ec47c453e0d7cb4e62d1d1f6c0efb43cc0bfb5.zip
gcc-e1ec47c453e0d7cb4e62d1d1f6c0efb43cc0bfb5.tar.gz
gcc-e1ec47c453e0d7cb4e62d1d1f6c0efb43cc0bfb5.tar.bz2
re PR middle-end/39246 (FAIL: gcc.dg/uninit-13.c)
2014-05-07 Thomas Preud'homme <thomas.preudhomme@arm.com> PR middle-end/39246 * tree-complex.c (expand_complex_move): Keep line info when expanding complex move. * tree-ssa-uninit.c (warn_uninit): New argument. Ignore assignment of complex expression. Use new argument to display correct location for values coming from phi statement. (warn_uninitialized_vars): Adapt to new signature of warn_uninit. (warn_uninitialized_phi): Pass location of phi argument to warn_uninit. * tree-ssa.c (ssa_undefined_value_p): For SSA_NAME initialized by a COMPLEX_EXPR, recurse on each part of the COMPLEX_EXPR. testsuite: * gcc.dg/uninit-13.c: Move warning on the actual source line where the uninitialized complex is used. * gcc.dg/uninit-17.c: New test to check partial initialization of complex with branches. * gcc.dg/uninit-17-O0.c: Likewise. From-SVN: r210199
Diffstat (limited to 'gcc/tree-ssa-uninit.c')
-rw-r--r--gcc/tree-ssa-uninit.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 96e9e60..8b298fa 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -123,17 +123,25 @@ uninit_undefined_value_p (tree t) {
/* Emit a warning for EXPR based on variable VAR at the point in the
program T, an SSA_NAME, is used being uninitialized. The exact
- warning text is in MSGID and LOCUS may contain a location or be null.
- WC is the warning code. */
+ warning text is in MSGID and DATA is the gimple stmt with info about
+ the location in source code. When DATA is a GIMPLE_PHI, PHIARG_IDX
+ gives which argument of the phi node to take the location from. WC
+ is the warning code. */
static void
-warn_uninit (enum opt_code wc, tree t,
- tree expr, tree var, const char *gmsgid, void *data)
+warn_uninit (enum opt_code wc, tree t, tree expr, tree var,
+ const char *gmsgid, void *data, location_t phiarg_loc)
{
gimple context = (gimple) data;
location_t location, cfun_loc;
expanded_location xloc, floc;
+ /* Ignore COMPLEX_EXPR as initializing only a part of a complex
+ turns in a COMPLEX_EXPR with the not initialized part being
+ set to its previous (undefined) value. */
+ if (is_gimple_assign (context)
+ && gimple_assign_rhs_code (context) == COMPLEX_EXPR)
+ return;
if (!has_undefined_value_p (t))
return;
@@ -146,9 +154,12 @@ warn_uninit (enum opt_code wc, tree t,
|| TREE_NO_WARNING (expr))
return;
- location = (context != NULL && gimple_has_location (context))
- ? gimple_location (context)
- : DECL_SOURCE_LOCATION (var);
+ if (context != NULL && gimple_has_location (context))
+ location = gimple_location (context);
+ else if (phiarg_loc != UNKNOWN_LOCATION)
+ location = phiarg_loc;
+ else
+ location = DECL_SOURCE_LOCATION (var);
location = linemap_resolve_location (line_table, location,
LRK_SPELLING_LOCATION,
NULL);
@@ -200,12 +211,12 @@ warn_uninitialized_vars (bool warn_possibly_uninitialized)
warn_uninit (OPT_Wuninitialized, use,
SSA_NAME_VAR (use), SSA_NAME_VAR (use),
"%qD is used uninitialized in this function",
- stmt);
+ stmt, UNKNOWN_LOCATION);
else if (warn_possibly_uninitialized)
warn_uninit (OPT_Wmaybe_uninitialized, use,
SSA_NAME_VAR (use), SSA_NAME_VAR (use),
"%qD may be used uninitialized in this function",
- stmt);
+ stmt, UNKNOWN_LOCATION);
}
/* For memory the only cheap thing we can do is see if we
@@ -236,12 +247,12 @@ warn_uninitialized_vars (bool warn_possibly_uninitialized)
warn_uninit (OPT_Wuninitialized, use,
gimple_assign_rhs1 (stmt), base,
"%qE is used uninitialized in this function",
- stmt);
+ stmt, UNKNOWN_LOCATION);
else if (warn_possibly_uninitialized)
warn_uninit (OPT_Wmaybe_uninitialized, use,
gimple_assign_rhs1 (stmt), base,
"%qE may be used uninitialized in this function",
- stmt);
+ stmt, UNKNOWN_LOCATION);
}
}
}
@@ -2246,6 +2257,8 @@ warn_uninitialized_phi (gimple phi, vec<gimple> *worklist,
unsigned uninit_opnds;
gimple uninit_use_stmt = 0;
tree uninit_op;
+ int phiarg_index;
+ location_t loc;
/* Don't look at virtual operands. */
if (virtual_operand_p (gimple_phi_result (phi)))
@@ -2270,13 +2283,18 @@ warn_uninitialized_phi (gimple phi, vec<gimple> *worklist,
if (!uninit_use_stmt)
return;
- uninit_op = gimple_phi_arg_def (phi, MASK_FIRST_SET_BIT (uninit_opnds));
+ phiarg_index = MASK_FIRST_SET_BIT (uninit_opnds);
+ uninit_op = gimple_phi_arg_def (phi, phiarg_index);
if (SSA_NAME_VAR (uninit_op) == NULL_TREE)
return;
+ if (gimple_phi_arg_has_location (phi, phiarg_index))
+ loc = gimple_phi_arg_location (phi, phiarg_index);
+ else
+ loc = UNKNOWN_LOCATION;
warn_uninit (OPT_Wmaybe_uninitialized, uninit_op, SSA_NAME_VAR (uninit_op),
SSA_NAME_VAR (uninit_op),
"%qD may be used uninitialized in this function",
- uninit_use_stmt);
+ uninit_use_stmt, loc);
}