Functions |
static int | get_mask_first_set_bit () |
bool | ssa_undefined_value_p () |
static bool | uninit_undefined_value_p () |
static bool | can_skip_redundant_opnd () |
static unsigned | compute_uninit_opnds_pos () |
static basic_block | find_pdom () |
static basic_block | find_dom () |
static bool | is_non_loop_exit_postdominating () |
static basic_block | find_control_equiv_block () |
static bool | compute_control_dep_chain (basic_block bb, basic_block dep_bb, vec< edge > *cd_chains, size_t *num_chains, vec< edge > *cur_cd_chain) |
static bool | convert_control_dep_chain_into_preds (vec< edge > *dep_chains, size_t num_chains, vec< use_pred_info_t > **preds, size_t *num_preds) |
static bool | find_predicates (vec< use_pred_info_t > **preds, size_t *num_preds, basic_block phi_bb, basic_block use_bb) |
static void | collect_phi_def_edges (gimple phi, basic_block cd_root, vec< edge > *edges, struct pointer_set_t *visited_phis) |
static bool | find_def_preds (vec< use_pred_info_t > **preds, size_t *num_preds, gimple phi) |
static void | dump_predicates (gimple usestmt, size_t num_preds, vec< use_pred_info_t > *preds, const char *msg) |
static void | destroy_predicate_vecs (size_t n, vec< use_pred_info_t > *preds) |
static enum tree_code | get_cmp_code (enum tree_code orig_cmp_code, bool swap_cond, bool invert) |
static bool | is_value_included_in () |
static bool | find_matching_predicate_in_rest_chains (use_pred_info_t pred, vec< use_pred_info_t > *preds, size_t num_pred_chains) |
static bool | is_use_properly_guarded (gimple use_stmt, basic_block use_bb, gimple phi, unsigned uninit_opnds, struct pointer_set_t *visited_phis) |
static bool | prune_uninit_phi_opnds_in_unrealizable_paths (gimple phi, unsigned uninit_opnds, gimple flag_def, tree boundary_cst, enum tree_code cmp_code, struct pointer_set_t *visited_phis, bitmap *visited_flag_phis) |
static bool | use_pred_not_overlap_with_undef_path_pred (size_t num_preds, vec< use_pred_info_t > *preds, gimple phi, unsigned uninit_opnds, struct pointer_set_t *visited_phis) |
static bool | is_and_or_or () |
static void | normalize_cond_1 (gimple cond, norm_cond_t norm_cond, enum tree_code cond_code) |
static void | normalize_cond () |
static bool | is_gcond_subset_of (gimple cond1, bool invert1, gimple cond2, bool invert2, bool reverse) |
static bool | is_subset_of_any (gimple cond, bool invert, norm_cond_t norm_cond, bool reverse) |
static bool | is_or_set_subset_of (norm_cond_t norm_cond1, norm_cond_t norm_cond2) |
static bool | is_and_set_subset_of (norm_cond_t norm_cond1, norm_cond_t norm_cond2) |
static bool | is_norm_cond_subset_of (norm_cond_t norm_cond1, norm_cond_t norm_cond2) |
static bool | is_pred_expr_subset_of (use_pred_info_t expr1, use_pred_info_t expr2) |
static bool | is_pred_chain_subset_of (vec< use_pred_info_t > pred1, vec< use_pred_info_t > pred2) |
static bool | is_included_in (vec< use_pred_info_t > one_pred, vec< use_pred_info_t > *preds, size_t n) |
static bool | is_superset_of (vec< use_pred_info_t > *preds1, size_t n1, vec< use_pred_info_t > *preds2, size_t n2) |
static int | pred_chain_length_cmp () |
static bool | normalize_preds () |
static gimple | find_uninit_use (gimple phi, unsigned uninit_opnds, vec< gimple > *worklist, struct pointer_set_t *added_to_worklist) |
static void | warn_uninitialized_phi (gimple phi, vec< gimple > *worklist, struct pointer_set_t *added_to_worklist) |
static unsigned int | execute_late_warn_uninitialized () |
static bool | gate_warn_uninitialized () |
gimple_opt_pass * | make_pass_late_warn_uninitialized () |
Computes the set of incoming edges of PHI that have non empty
definitions of a phi chain. The collection will be done
recursively on operands that are defined by phis. CD_ROOT
is the control dependence root. *EDGES holds the result, and
VISITED_PHIS is a pointer set for detecting cycles.
References CDI_DOMINATORS, dominated_by_p(), dump_file, dump_flags, gimple_phi_arg_def(), gimple_phi_arg_edge(), gimple_phi_num_args(), pointer_set_insert(), print_gimple_stmt(), and uninit_undefined_value_p().
Referenced by find_def_preds().
static bool convert_control_dep_chain_into_preds |
( |
vec< edge > * |
dep_chains, |
|
|
size_t |
num_chains, |
|
|
vec< use_pred_info_t > ** |
preds, |
|
|
size_t * |
num_preds |
|
) |
| |
|
static |
Converts the chains of control dependence edges into a set of
predicates. A control dependence chain is represented by a vector
edges. DEP_CHAINS points to an array of dependence chains.
NUM_CHAINS is the size of the chain array. One edge in a dependence
chain is mapped to predicate expression represented by use_pred_info_t
type. One dependence chain is converted to a composite predicate that
is the result of AND operation of use_pred_info_t mapped to each edge.
A composite predicate is presented by a vector of use_pred_info_t. On
return, *PREDS points to the resulting array of composite predicates.
*NUM_PREDS is the number of composite predictes.
References use_pred_info::cond, edge_def::dest, edge_def::flags, gsi_end_p(), gsi_last_bb(), gsi_stmt(), use_pred_info::invert, edge_def::src, and basic_block_def::succs.
Referenced by find_def_preds(), and find_predicates().
Searches through all uses of a potentially
uninitialized variable defined by PHI and returns a use
statement if the use is not properly guarded. It returns
NULL if all uses are guarded. UNINIT_OPNDS is a bitvector
holding the position(s) of uninit PHI operands. WORKLIST
is the vector of candidate phis that may be updated by this
function. ADDED_TO_WORKLIST is the pointer set tracking
if the new phi is already in the worklist.
References dump_file, dump_flags, gimple_bb(), gimple_phi_arg_edge(), gimple_phi_result(), is_gimple_debug(), is_use_properly_guarded(), pointer_set_create(), pointer_set_destroy(), pointer_set_insert(), print_gimple_stmt(), and edge_def::src.
Referenced by warn_uninitialized_phi().
static bool is_subset_of_any |
( |
gimple |
cond, |
|
|
bool |
invert, |
|
|
norm_cond_t |
norm_cond, |
|
|
bool |
reverse |
|
) |
| |
|
static |
compares two predicate sets PREDS1 and PREDS2 and returns
true if the domain defined by PREDS1 is a superset
of PREDS2's domain. N1 and N2 are array sizes of PREDS1 and
PREDS2 respectively. The implementation chooses not to build
generic trees (and relying on the folding capability of the
compiler), but instead performs brute force comparison of
individual predicate chains (won't be a compile time problem
as the chains are pretty short). When the function returns
false, it does not necessarily mean *PREDS1 is not a superset
of *PREDS2, but mean it may not be so since the analysis can
not prove it. In such cases, false warnings may still be
emitted.
References is_included_in().
Referenced by is_use_properly_guarded().
Forward declaration.
Computes the predicates that guard the use and checks
if the incoming paths that have empty (or possibly
empty) definition can be pruned/filtered. The function returns
true if it can be determined that the use of PHI's def in
USE_STMT is guarded with a predicate set not overlapping with
predicate sets of all runtime paths that do not have a definition.
Returns false if it is not or it can not be determined. USE_BB is
the bb of the use (for phi operand use, the bb is not the bb of
the phi stmt, but the src bb of the operand edge). UNINIT_OPNDS
is a bit vector. If an operand of PHI is uninitialized, the
corresponding bit in the vector is 1. VISIED_PHIS is a pointer
set of phis being visted.
References destroy_predicate_vecs(), dump_file, dump_predicates(), find_def_preds(), find_predicates(), gimple_bb(), is_non_loop_exit_postdominating(), is_superset_of(), normalize_preds(), pointer_set_insert(), and use_pred_not_overlap_with_undef_path_pred().
Referenced by find_uninit_use(), and prune_uninit_phi_opnds_in_unrealizable_paths().
static bool prune_uninit_phi_opnds_in_unrealizable_paths |
( |
gimple |
phi, |
|
|
unsigned |
uninit_opnds, |
|
|
gimple |
flag_def, |
|
|
tree |
boundary_cst, |
|
|
enum tree_code |
cmp_code, |
|
|
struct pointer_set_t * |
visited_phis, |
|
|
bitmap * |
visited_flag_phis |
|
) |
| |
|
static |
Returns true if all uninitialized opnds are pruned. Returns false
otherwise. PHI is the phi node with uninitialized operands,
UNINIT_OPNDS is the bitmap of the uninitialize operand positions,
FLAG_DEF is the statement defining the flag guarding the use of the
PHI output, BOUNDARY_CST is the const value used in the predicate
associated with the flag, CMP_CODE is the comparison code used in
the predicate, VISITED_PHIS is the pointer set of phis visited, and
VISITED_FLAG_PHIS is the pointer to the pointer set of flag definitions
that are also phis.
Example scenario:
BB1:
flag_1 = phi <0, 1> // (1)
var_1 = phi <undef, some_val>
BB2:
flag_2 = phi <0, flag_1, flag_1> // (2)
var_2 = phi <undef, var_1, var_1>
if (flag_2 == 1)
goto BB3;
BB3:
use of var_2 // (3)
Because some flag arg in (1) is not constant, if we do not look into the
flag phis recursively, it is conservatively treated as unknown and var_1
is thought to be flowed into use at (3). Since var_1 is potentially uninitialized
a false warning will be emitted. Checking recursively into (1), the compiler can
find out that only some_val (which is defined) can flow into (3) which is OK.
References bitmap_bit_p(), bitmap_clear_bit(), bitmap_set_bit(), compute_uninit_opnds_pos(), gimple_phi_arg_def(), gimple_phi_arg_edge(), gimple_phi_num_args(), gimple_phi_result(), is_gimple_constant(), is_use_properly_guarded(), is_value_included_in(), and edge_def::src.
Referenced by use_pred_not_overlap_with_undef_path_pred().
A helper function that determines if the predicate set
of the use is not overlapping with that of the uninit paths.
The most common senario of guarded use is in Example 1:
Example 1:
if (some_cond)
{
x = ...;
flag = true;
}
... some code ...
if (flag)
use (x);
The real world examples are usually more complicated, but similar
and usually result from inlining:
bool init_func (int * x)
{
if (some_cond)
return false;
*x = ..
return true;
}
void foo(..)
{
int x;
if (!init_func(&x))
return;
.. some_code ...
use (x);
}
Another possible use scenario is in the following trivial example:
Example 2:
if (n > 0)
x = 1;
...
if (n > 0)
{
if (m < 2)
.. = x;
}
Predicate analysis needs to compute the composite predicate:
1) 'x' use predicate: (n > 0) .AND. (m < 2)
2) 'x' default value (non-def) predicate: .NOT. (n > 0)
(the predicate chain for phi operand defs can be computed
starting from a bb that is control equivalent to the phi's
bb and is dominating the operand def.)
and check overlapping:
(n > 0) .AND. (m < 2) .AND. (.NOT. (n > 0))
<==> false
This implementation provides framework that can handle
scenarios. (Note that many simple cases are handled properly
without the predicate analysis -- this is due to jump threading
transformation which eliminates the merge point thus makes
path sensitive analysis unnecessary.)
NUM_PREDS is the number is the number predicate chains, PREDS is
the array of chains, PHI is the phi node whose incoming (undefined)
paths need to be pruned, and UNINIT_OPNDS is the bitmap holding
uninit operand positions. VISITED_PHIS is the pointer set of phi
stmts being checked.
References use_pred_info::cond, find_matching_predicate_in_rest_chains(), get_cmp_code(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), use_pred_info::invert, is_gimple_constant(), and prune_uninit_phi_opnds_in_unrealizable_paths().
Referenced by is_use_properly_guarded().
Look for inputs to PHI that are SSA_NAMEs that have empty definitions
and gives warning if there exists a runtime path from the entry to a
use of the PHI def that does not contain a definition. In other words,
the warning is on the real use. The more dead paths that can be pruned
by the compiler, the fewer false positives the warning is. WORKLIST
is a vector of candidate phis to be examined. ADDED_TO_WORKLIST is
a pointer set tracking if the new phi is added to the worklist or not.
References compute_uninit_opnds_pos(), dump_file, dump_flags, find_uninit_use(), gimple_phi_arg_def(), gimple_phi_result(), print_gimple_stmt(), virtual_operand_p(), and warn_uninit().
Referenced by execute_late_warn_uninitialized().
@verbatim Predicate aware uninitialized variable warning.
Copyright (C) 2001-2013 Free Software Foundation, Inc. Contributed by Xinliang David Li david.nosp@m.xl@g.nosp@m.oogle.nosp@m..com
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.
This implements the pass that does predicate aware warning on uses of
possibly uninitialized variables. The pass first collects the set of
possibly uninitialized SSA names. For each such name, it walks through
all its immediate uses. For each immediate use, it rebuilds the condition
expression (the predicate) that guards the use. The predicate is then
examined to see if the variable is always defined under that same condition.
This is done either by pruning the unrealizable paths that lead to the
default definitions or by checking if the predicate set that guards the
defining paths is a superset of the use predicate.
Pointer set of potentially undefined ssa names, i.e.,
ssa names that are defined by phi with operands that
are not defined or potentially undefined.