diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-09-13 10:37:49 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-09-13 10:37:49 -0700 |
commit | e252b51ccde010cbd2a146485d8045103cd99533 (patch) | |
tree | e060f101cdc32bf5e520de8e5275db9d4236b74c /gcc/tree-ssa-uninit.c | |
parent | f10c7c4596dda99d2ee872c995ae4aeda65adbdf (diff) | |
parent | 104c05c5284b7822d770ee51a7d91946c7e56d50 (diff) | |
download | gcc-e252b51ccde010cbd2a146485d8045103cd99533.zip gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.gz gcc-e252b51ccde010cbd2a146485d8045103cd99533.tar.bz2 |
Merge from trunk revision 104c05c5284b7822d770ee51a7d91946c7e56d50.
Diffstat (limited to 'gcc/tree-ssa-uninit.c')
-rw-r--r-- | gcc/tree-ssa-uninit.c | 549 |
1 files changed, 419 insertions, 130 deletions
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 0800f59..84eadd1 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "builtins.h" #include "calls.h" +#include "gimple-range.h" /* This implements the pass that does predicate aware warning on uses of possibly uninitialized variables. The pass first collects the set of @@ -86,17 +87,33 @@ has_undefined_value_p (tree t) && possibly_undefined_names->contains (t))); } -/* Like has_undefined_value_p, but don't return true if TREE_NO_WARNING - is set on SSA_NAME_VAR. */ +/* Return true if EXPR should suppress either uninitialized warning. */ + +static inline bool +get_no_uninit_warning (tree expr) +{ + return warning_suppressed_p (expr, OPT_Wuninitialized); +} + +/* Suppress both uninitialized warnings for EXPR. */ + +static inline void +set_no_uninit_warning (tree expr) +{ + suppress_warning (expr, OPT_Wuninitialized); +} + +/* Like has_undefined_value_p, but don't return true if the no-warning + bit is set on SSA_NAME_VAR for either uninit warning. */ static inline bool uninit_undefined_value_p (tree t) { if (!has_undefined_value_p (t)) return false; - if (SSA_NAME_VAR (t) && TREE_NO_WARNING (SSA_NAME_VAR (t))) - return false; - return true; + if (!SSA_NAME_VAR (t)) + return true; + return !get_no_uninit_warning (SSA_NAME_VAR (t)); } /* Emit warnings for uninitialized variables. This is done in two passes. @@ -114,20 +131,19 @@ uninit_undefined_value_p (tree t) again for plain uninitialized variables, since optimization may have changed conditionally uninitialized to unconditionally uninitialized. */ -/* 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 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. */ +/* Emit warning OPT for variable VAR at the point in the program where + the SSA_NAME T is being used uninitialized. The warning text is in + MSGID and STMT is the statement that does the uninitialized read. + PHI_ARG_LOC is the location of the PHI argument if T and VAR are one, + or UNKNOWN_LOCATION otherwise. */ static void -warn_uninit (enum opt_code wc, tree t, tree expr, tree var, - const char *gmsgid, void *data, location_t phiarg_loc) +warn_uninit (opt_code opt, tree t, tree var, const char *gmsgid, + gimple *context, location_t phi_arg_loc = UNKNOWN_LOCATION) { - gimple *context = (gimple *) data; - location_t location, cfun_loc; - expanded_location xloc, floc; + /* Bail if the value isn't provably uninitialized. */ + if (!has_undefined_value_p (t)) + return; /* Ignore COMPLEX_EXPR as initializing only a part of a complex turns in a COMPLEX_EXPR with the not initialized part being @@ -135,65 +151,98 @@ warn_uninit (enum opt_code wc, tree t, tree expr, tree var, if (is_gimple_assign (context) && gimple_assign_rhs_code (context) == COMPLEX_EXPR) return; - if (!has_undefined_value_p (t)) - return; + + /* Ignore REALPART_EXPR or IMAGPART_EXPR if its operand is a call to + .DEFERRED_INIT. This is for handling the following case correctly: + + 1 typedef _Complex float C; + 2 C foo (int cond) + 3 { + 4 C f; + 5 __imag__ f = 0; + 6 if (cond) + 7 { + 8 __real__ f = 1; + 9 return f; + 10 } + 11 return f; + 12 } + + with -ftrivial-auto-var-init, compiler will insert the following + artificial initialization at line 4: + f = .DEFERRED_INIT (f, 2); + _1 = REALPART_EXPR <f>; + + without the following special handling, _1 = REALPART_EXPR <f> will + be treated as the uninitialized use point, which is incorrect. (the + real uninitialized use point is at line 11). */ + if (is_gimple_assign (context) + && (gimple_assign_rhs_code (context) == REALPART_EXPR + || gimple_assign_rhs_code (context) == IMAGPART_EXPR)) + { + tree v = gimple_assign_rhs1 (context); + if (TREE_CODE (TREE_OPERAND (v, 0)) == SSA_NAME + && gimple_call_internal_p (SSA_NAME_DEF_STMT (TREE_OPERAND (v, 0)), + IFN_DEFERRED_INIT)) + return; + } /* Anonymous SSA_NAMEs shouldn't be uninitialized, but ssa_undefined_value_p - can return true if the def stmt of anonymous SSA_NAME is COMPLEX_EXPR + can return true if the def stmt of an anonymous SSA_NAME is COMPLEX_EXPR created for conversion from scalar to complex. Use the underlying var of the COMPLEX_EXPRs real part in that case. See PR71581. */ - if (expr == NULL_TREE - && var == NULL_TREE - && SSA_NAME_VAR (t) == NULL_TREE - && is_gimple_assign (SSA_NAME_DEF_STMT (t)) - && gimple_assign_rhs_code (SSA_NAME_DEF_STMT (t)) == COMPLEX_EXPR) - { - tree v = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (t)); - if (TREE_CODE (v) == SSA_NAME - && has_undefined_value_p (v) - && zerop (gimple_assign_rhs2 (SSA_NAME_DEF_STMT (t)))) + if (!var && !SSA_NAME_VAR (t)) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (t); + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == COMPLEX_EXPR) { - expr = SSA_NAME_VAR (v); - var = expr; + tree v = gimple_assign_rhs1 (def_stmt); + if (TREE_CODE (v) == SSA_NAME + && has_undefined_value_p (v) + && zerop (gimple_assign_rhs2 (def_stmt))) + var = SSA_NAME_VAR (v); } } - if (expr == NULL_TREE) + if (var == NULL_TREE) return; - /* TREE_NO_WARNING either means we already warned, or the front end - wishes to suppress the warning. */ - if ((context - && (gimple_no_warning_p (context) - || (gimple_assign_single_p (context) - && TREE_NO_WARNING (gimple_assign_rhs1 (context))))) - || TREE_NO_WARNING (expr)) + /* Avoid warning if we've already done so or if the warning has been + suppressed. */ + if (((warning_suppressed_p (context, OPT_Wuninitialized) + || (gimple_assign_single_p (context) + && get_no_uninit_warning (gimple_assign_rhs1 (context))))) + || get_no_uninit_warning (var)) return; - if (context != NULL && gimple_has_location (context)) + /* Use either the location of the read statement or that of the PHI + argument, or that of the uninitialized variable, in that order, + whichever is valid. */ + location_t location; + if (gimple_has_location (context)) location = gimple_location (context); - else if (phiarg_loc != UNKNOWN_LOCATION) - location = phiarg_loc; + else if (phi_arg_loc != UNKNOWN_LOCATION) + location = phi_arg_loc; else location = DECL_SOURCE_LOCATION (var); location = linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, NULL); - cfun_loc = DECL_SOURCE_LOCATION (cfun->decl); - xloc = expand_location (location); - floc = expand_location (cfun_loc); + auto_diagnostic_group d; - if (warning_at (location, wc, gmsgid, expr)) - { - TREE_NO_WARNING (expr) = 1; + if (!warning_at (location, opt, gmsgid, var)) + return; - if (location == DECL_SOURCE_LOCATION (var)) - return; - if (xloc.file != floc.file - || linemap_location_before_p (line_table, location, cfun_loc) - || linemap_location_before_p (line_table, cfun->function_end_locus, - location)) - inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); - } + /* Avoid subsequent warnings for reads of the same variable again. */ + suppress_warning (var, opt); + + /* Issue a note pointing to the read variable unless the warning + is at the same location. */ + location_t var_loc = DECL_SOURCE_LOCATION (var); + if (location == var_loc) + return; + + inform (var_loc, "%qD was declared here", var); } struct check_defs_data @@ -202,6 +251,128 @@ struct check_defs_data bool found_may_defs; }; +/* Return true if STMT is a call to built-in function all of whose + by-reference arguments are const-qualified (i.e., the function can + be assumed not to modify them). */ + +static bool +builtin_call_nomodifying_p (gimple *stmt) +{ + if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) + return false; + + tree fndecl = gimple_call_fndecl (stmt); + if (!fndecl) + return false; + + tree fntype = TREE_TYPE (fndecl); + if (!fntype) + return false; + + /* Check the called function's signature for non-constc pointers. + If one is found, return false. */ + unsigned argno = 0; + tree argtype; + function_args_iterator it; + FOREACH_FUNCTION_ARGS (fntype, argtype, it) + { + if (VOID_TYPE_P (argtype)) + return true; + + ++argno; + + if (!POINTER_TYPE_P (argtype)) + continue; + + if (TYPE_READONLY (TREE_TYPE (argtype))) + continue; + + return false; + } + + /* If the number of actual arguments to the call is less than or + equal to the number of parameters, return false. */ + unsigned nargs = gimple_call_num_args (stmt); + if (nargs <= argno) + return false; + + /* Check arguments passed through the ellipsis in calls to variadic + functions for pointers. If one is found that's a non-constant + pointer, return false. */ + for (; argno < nargs; ++argno) + { + tree arg = gimple_call_arg (stmt, argno); + argtype = TREE_TYPE (arg); + if (!POINTER_TYPE_P (argtype)) + continue; + + if (TYPE_READONLY (TREE_TYPE (argtype))) + continue; + + return false; + } + + return true; +} + +/* If ARG is a FNDECL parameter declared with attribute access none or + write_only issue a warning for its read access via PTR. */ + +static void +maybe_warn_read_write_only (tree fndecl, gimple *stmt, tree arg, tree ptr) +{ + if (!fndecl) + return; + + if (get_no_uninit_warning (arg)) + return; + + tree fntype = TREE_TYPE (fndecl); + if (!fntype) + return; + + /* Initialize a map of attribute access specifications for arguments + to the function function call. */ + rdwr_map rdwr_idx; + init_attr_rdwr_indices (&rdwr_idx, TYPE_ATTRIBUTES (fntype)); + + unsigned argno = 0; + tree parms = DECL_ARGUMENTS (fndecl); + for (tree parm = parms; parm; parm = TREE_CHAIN (parm), ++argno) + { + if (parm != arg) + continue; + + const attr_access* access = rdwr_idx.get (argno); + if (!access) + break; + + if (access->mode != access_none + && access->mode != access_write_only) + continue; + + location_t stmtloc + = linemap_resolve_location (line_table, gimple_location (stmt), + LRK_SPELLING_LOCATION, NULL); + + if (!warning_at (stmtloc, OPT_Wmaybe_uninitialized, + "%qE may be used uninitialized", ptr)) + break; + + suppress_warning (arg, OPT_Wmaybe_uninitialized); + + const char* const access_str = + TREE_STRING_POINTER (access->to_external_string ()); + + location_t parmloc = DECL_SOURCE_LOCATION (parm); + inform (parmloc, "accessing argument %u of a function declared with " + "attribute %<%s%>", + argno + 1, access_str); + + break; + } +} + /* Callback for walk_aliased_vdefs. */ static bool @@ -209,6 +380,38 @@ check_defs (ao_ref *ref, tree vdef, void *data_) { check_defs_data *data = (check_defs_data *)data_; gimple *def_stmt = SSA_NAME_DEF_STMT (vdef); + + /* Ignore the vdef if the definition statement is a call + to .DEFERRED_INIT function. */ + if (gimple_call_internal_p (def_stmt, IFN_DEFERRED_INIT)) + return false; + + /* The ASAN_MARK intrinsic doesn't modify the variable. */ + if (is_gimple_call (def_stmt)) + { + if (gimple_call_internal_p (def_stmt) + && gimple_call_internal_fn (def_stmt) == IFN_ASAN_MARK) + return false; + + if (tree fndecl = gimple_call_fndecl (def_stmt)) + { + /* Some sanitizer calls pass integer arguments to built-ins + that expect pointers. Avoid using gimple_call_builtin_p() + which fails for such calls. */ + if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + { + built_in_function fncode = DECL_FUNCTION_CODE (fndecl); + if (fncode > BEGIN_SANITIZER_BUILTINS + && fncode < END_SANITIZER_BUILTINS) + return false; + } + } + } + + /* End of VLA scope is not a kill. */ + if (gimple_call_builtin_p (def_stmt, BUILT_IN_STACK_RESTORE)) + return false; + /* If this is a clobber then if it is not a kill walk past it. */ if (gimple_clobber_p (def_stmt)) { @@ -216,6 +419,10 @@ check_defs (ao_ref *ref, tree vdef, void *data_) return true; return false; } + + if (builtin_call_nomodifying_p (def_stmt)) + return false; + /* Found a may-def on this path. */ data->found_may_defs = true; return true; @@ -238,7 +445,9 @@ struct wlimits }; /* Determine if REF references an uninitialized operand and diagnose - it if so. */ + it if so. STMS is the referencing statement. LHS is the result + of the access and may be null. RHS is the variable referenced by + the access; it may not be null. */ static tree maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, @@ -248,7 +457,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, use_operand_p luse_p; imm_use_iterator liter; - if (TREE_NO_WARNING (rhs)) + if (get_no_uninit_warning (rhs)) return NULL_TREE; /* Do not warn if the base was marked so or this is a @@ -256,19 +465,23 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, tree base = ao_ref_base (&ref); if ((VAR_P (base) && DECL_HARD_REGISTER (base)) - || TREE_NO_WARNING (base)) + || get_no_uninit_warning (base)) return NULL_TREE; - /* Do not warn if the access is fully outside of the variable. */ + /* Do not warn if the access is zero size or if it's fully outside + the object. */ poly_int64 decl_size; + if (known_size_p (ref.size) + && known_eq (ref.max_size, ref.size) + && (known_eq (ref.size, 0) + || known_le (ref.offset + ref.size, 0))) + return NULL_TREE; + if (DECL_P (base) - && ((known_size_p (ref.size) - && known_eq (ref.max_size, ref.size) - && known_le (ref.offset + ref.size, 0)) - || (known_ge (ref.offset, 0) - && DECL_SIZE (base) - && poly_int_tree_p (DECL_SIZE (base), &decl_size) - && known_le (decl_size, ref.offset)))) + && known_ge (ref.offset, 0) + && DECL_SIZE (base) + && poly_int_tree_p (DECL_SIZE (base), &decl_size) + && known_le (decl_size, ref.offset)) return NULL_TREE; /* Do not warn if the result of the access is then used for @@ -381,21 +594,32 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, /* Do not warn if it can be initialized outside this function. If we did not reach function entry then we found killing clobbers on all paths to entry. */ - if (!found_alloc - && fentry_reached - /* ??? We'd like to use ref_may_alias_global_p but that - excludes global readonly memory and thus we get bogus - warnings from p = cond ? "a" : "b" for example. */ - && (!VAR_P (base) - || is_global_var (base))) - return NULL_TREE; + if (!found_alloc && fentry_reached) + { + if (TREE_CODE (base) == SSA_NAME) + { + tree var = SSA_NAME_VAR (base); + if (var && TREE_CODE (var) == PARM_DECL) + { + maybe_warn_read_write_only (cfun->decl, stmt, var, rhs); + return NULL_TREE; + } + } + + if (!VAR_P (base) + || is_global_var (base)) + /* ??? We'd like to use ref_may_alias_global_p but that + excludes global readonly memory and thus we get bogus + warnings from p = cond ? "a" : "b" for example. */ + return NULL_TREE; + } /* Strip the address-of expression from arrays passed to functions. */ if (TREE_CODE (rhs) == ADDR_EXPR) rhs = TREE_OPERAND (rhs, 0); /* Check again since RHS may have changed above. */ - if (TREE_NO_WARNING (rhs)) + if (get_no_uninit_warning (rhs)) return NULL_TREE; /* Avoid warning about empty types such as structs with no members. @@ -416,20 +640,20 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, if (wlims.always_executed) { if (warning_at (location, OPT_Wuninitialized, - "%G%qE is used uninitialized", stmt, rhs)) + "%qE is used uninitialized", rhs)) { /* ??? This is only effective for decls as in gcc.dg/uninit-B-O0.c. Avoid doing this for maybe-uninit uses or accesses by functions as it may hide important locations. */ if (lhs) - TREE_NO_WARNING (rhs) = 1; + set_no_uninit_warning (rhs); warned = true; } } else if (wlims.wmaybe_uninit) warned = warning_at (location, OPT_Wmaybe_uninitialized, - "%G%qE may be used uninitialized", stmt, rhs); + "%qE may be used uninitialized", rhs); return warned ? base : NULL_TREE; } @@ -525,10 +749,13 @@ maybe_warn_pass_by_reference (gcall *stmt, wlimits &wlims) wlims.always_executed = false; /* Ignore args we are not going to read from. */ - if (gimple_call_arg_flags (stmt, argno - 1) & EAF_UNUSED) + if (gimple_call_arg_flags (stmt, argno - 1) & (EAF_UNUSED | EAF_NOREAD)) continue; tree arg = gimple_call_arg (stmt, argno - 1); + if (!POINTER_TYPE_P (TREE_TYPE (arg))) + /* Avoid actual arguments with invalid types. */ + continue; ao_ref ref; ao_ref_init_from_ptr_and_size (&ref, arg, access_size); @@ -590,8 +817,79 @@ maybe_warn_pass_by_reference (gcall *stmt, wlimits &wlims) wlims.always_executed = save_always_executed; } +/* Warn about an uninitialized PHI argument on the fallthru path to + an always executed block BB. */ -static unsigned int +static void +warn_uninit_phi_uses (basic_block bb) +{ + edge_iterator ei; + edge e, found = NULL, found_back = NULL; + /* Look for a fallthru and possibly a single backedge. */ + FOR_EACH_EDGE (e, ei, bb->preds) + { + /* Ignore backedges. */ + if (dominated_by_p (CDI_DOMINATORS, e->src, bb)) + { + if (found_back) + { + found = NULL; + break; + } + found_back = e; + continue; + } + if (found) + { + found = NULL; + break; + } + found = e; + } + if (!found) + return; + + basic_block succ = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si); + gsi_next (&si)) + { + gphi *phi = si.phi (); + tree def = PHI_ARG_DEF_FROM_EDGE (phi, found); + if (TREE_CODE (def) != SSA_NAME + || !SSA_NAME_IS_DEFAULT_DEF (def) + || virtual_operand_p (def)) + continue; + /* If there's a default def on the fallthru edge PHI + value and there's a use that post-dominates entry + then that use is uninitialized and we can warn. */ + imm_use_iterator iter; + use_operand_p use_p; + gimple *use_stmt = NULL; + FOR_EACH_IMM_USE_FAST (use_p, iter, gimple_phi_result (phi)) + { + use_stmt = USE_STMT (use_p); + if (gimple_location (use_stmt) != UNKNOWN_LOCATION + && dominated_by_p (CDI_POST_DOMINATORS, succ, + gimple_bb (use_stmt)) + /* If we found a non-fallthru edge make sure the + use is inside the loop, otherwise the backedge + can serve as initialization. */ + && (!found_back + || dominated_by_p (CDI_DOMINATORS, found_back->src, + gimple_bb (use_stmt)))) + break; + use_stmt = NULL; + } + if (use_stmt) + warn_uninit (OPT_Wuninitialized, def, SSA_NAME_VAR (def), + "%qD is used uninitialized", use_stmt); + } +} + +/* Issue warnings about reads of uninitialized variables. WMAYBE_UNINIT + is true to issue -Wmaybe-uninitialized, otherwise -Wuninitialized. */ + +static void warn_uninitialized_vars (bool wmaybe_uninit) { /* Counters and limits controlling the the depth of the warning. */ @@ -604,18 +902,27 @@ warn_uninitialized_vars (bool wmaybe_uninit) { basic_block succ = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); wlims.always_executed = dominated_by_p (CDI_POST_DOMINATORS, succ, bb); + + if (wlims.always_executed) + warn_uninit_phi_uses (bb); + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - use_operand_p use_p; - ssa_op_iter op_iter; - tree use; + + /* The call is an artificial use, will not provide meaningful + error message. If the result of the call is used somewhere + else, we warn there instead. */ + if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT)) + continue; if (is_gimple_debug (stmt)) continue; /* We only do data flow with SSA_NAMEs, so that's all we can warn about. */ + use_operand_p use_p; + ssa_op_iter op_iter; FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE) { /* BIT_INSERT_EXPR first operand should not be considered @@ -626,17 +933,13 @@ warn_uninitialized_vars (bool wmaybe_uninit) && use_p->use == gimple_assign_rhs1_ptr (ass)) continue; } - use = USE_FROM_PTR (use_p); + tree use = USE_FROM_PTR (use_p); if (wlims.always_executed) warn_uninit (OPT_Wuninitialized, use, SSA_NAME_VAR (use), - SSA_NAME_VAR (use), - "%qD is used uninitialized", stmt, - UNKNOWN_LOCATION); + "%qD is used uninitialized", stmt); else if (wmaybe_uninit) warn_uninit (OPT_Wmaybe_uninitialized, use, SSA_NAME_VAR (use), - SSA_NAME_VAR (use), - "%qD may be used uninitialized", - stmt, UNKNOWN_LOCATION); + "%qD may be used uninitialized", stmt); } /* For limiting the alias walk below we count all @@ -666,8 +969,6 @@ warn_uninitialized_vars (bool wmaybe_uninit) } } } - - return 0; } /* Checks if the operand OPND of PHI is defined by @@ -679,16 +980,13 @@ warn_uninitialized_vars (bool wmaybe_uninit) static bool can_skip_redundant_opnd (tree opnd, gimple *phi) { - gimple *op_def; - tree phi_def; - int i, n; - - phi_def = gimple_phi_result (phi); - op_def = SSA_NAME_DEF_STMT (opnd); + tree phi_def = gimple_phi_result (phi); + gimple *op_def = SSA_NAME_DEF_STMT (opnd); if (gimple_code (op_def) != GIMPLE_PHI) return false; - n = gimple_phi_num_args (op_def); - for (i = 0; i < n; ++i) + + unsigned n = gimple_phi_num_args (op_def); + for (unsigned i = 0; i < n; ++i) { tree op = gimple_phi_arg_def (op_def, i); if (TREE_CODE (op) != SSA_NAME) @@ -706,15 +1004,14 @@ can_skip_redundant_opnd (tree opnd, gimple *phi) static unsigned compute_uninit_opnds_pos (gphi *phi) { - size_t i, n; unsigned uninit_opnds = 0; - n = gimple_phi_num_args (phi); + unsigned n = gimple_phi_num_args (phi); /* Bail out for phi with too many args. */ if (n > max_phi_args) return 0; - for (i = 0; i < n; ++i) + for (unsigned i = 0; i < n; ++i) { tree op = gimple_phi_arg_def (phi, i); if (TREE_CODE (op) == SSA_NAME @@ -734,8 +1031,7 @@ compute_uninit_opnds_pos (gphi *phi) return uninit_opnds; } -/* Find the immediate postdominator PDOM of the specified - basic block BLOCK. */ +/* Find the immediate postdominator of the specified basic block BLOCK. */ static inline basic_block find_pdom (basic_block block) @@ -751,7 +1047,7 @@ find_pdom (basic_block block) } } -/* Find the immediate DOM of the specified basic block BLOCK. */ +/* Find the immediate dominator of the specified basic block BLOCK. */ static inline basic_block find_dom (basic_block block) @@ -789,9 +1085,7 @@ is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2) static inline basic_block find_control_equiv_block (basic_block bb) { - basic_block pdom; - - pdom = find_pdom (bb); + basic_block pdom = find_pdom (bb); /* Skip the postdominating bb that is also loop exit. */ if (!is_non_loop_exit_postdominating (pdom, bb)) @@ -1595,11 +1889,14 @@ find_var_cmp_const (pred_chain_union preds, gphi *phi, gimple **flag_def, flag_var <= [min, max] -> flag_var < [min, max+1] flag_var >= [min, max] -> flag_var > [min-1, max] if no overflow/wrap. */ - wide_int min, max; tree type = TREE_TYPE (cond_lhs); + value_range r; if (!INTEGRAL_TYPE_P (type) - || get_range_info (cond_rhs, &min, &max) != VR_RANGE) + || !get_range_query (cfun)->range_of_expr (r, cond_rhs) + || r.kind () != VR_RANGE) continue; + wide_int min = r.lower_bound (); + wide_int max = r.upper_bound (); if (code == LE_EXPR && max != wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type))) { @@ -2926,18 +3223,11 @@ static void warn_uninitialized_phi (gphi *phi, vec<gphi *> *worklist, hash_set<gphi *> *added_to_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))) return; - uninit_opnds = compute_uninit_opnds_pos (phi); - + unsigned uninit_opnds = compute_uninit_opnds_pos (phi); if (MASK_EMPTY (uninit_opnds)) return; @@ -2948,25 +3238,23 @@ warn_uninitialized_phi (gphi *phi, vec<gphi *> *worklist, } /* Now check if we have any use of the value without proper guard. */ - uninit_use_stmt = find_uninit_use (phi, uninit_opnds, - worklist, added_to_worklist); + gimple *uninit_use_stmt = find_uninit_use (phi, uninit_opnds, + worklist, added_to_worklist); /* All uses are properly guarded. */ if (!uninit_use_stmt) return; - phiarg_index = MASK_FIRST_SET_BIT (uninit_opnds); - uninit_op = gimple_phi_arg_def (phi, phiarg_index); + int phiarg_index = MASK_FIRST_SET_BIT (uninit_opnds); + tree 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), + + location_t phi_arg_loc = gimple_phi_arg_location (phi, phiarg_index); + warn_uninit (OPT_Wmaybe_uninitialized, uninit_op, SSA_NAME_VAR (uninit_op), "%qD may be used uninitialized in this function", - uninit_use_stmt, loc); + uninit_use_stmt, phi_arg_loc); } static bool @@ -3084,6 +3372,7 @@ execute_early_warn_uninitialized (void) optimization we want to warn about possible uninitialized as late as possible, thus don't do it here. However, without optimization we need to warn here about "may be uninitialized". */ + calculate_dominance_info (CDI_DOMINATORS); calculate_dominance_info (CDI_POST_DOMINATORS); warn_uninitialized_vars (/*warn_maybe_uninitialized=*/!optimize); |