GCC Middle and Back End API Reference
|
Data Structures | |
struct | use_pred_info |
struct | norm_cond |
Typedefs | |
typedef struct use_pred_info * | use_pred_info_t |
typedef struct norm_cond * | norm_cond_t |
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 () |
Variables | |
static struct pointer_set_t * | possibly_undefined_names = 0 |
typedef struct norm_cond * norm_cond_t |
typedef struct use_pred_info * use_pred_info_t |
|
static |
Checks if the operand OPND of PHI is defined by another phi with one operand defined by this PHI, but the rest operands are all defined. If yes, returns true to skip this this operand as being redundant. Can be enhanced to be more general.
References gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), and uninit_undefined_value_p().
Referenced by compute_uninit_opnds_pos().
|
static |
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 |
Computes the control dependence chains (paths of edges) for DEP_BB up to the dominating basic block BB (the head node of a chain should be dominated by it). CD_CHAINS is pointer to a dynamic array holding the result chains. CUR_CD_CHAIN is the current chain being computed. *NUM_CHAINS is total number of chains. The function returns true if the information is successfully computed, return false if there is no control dependence or not computed.
References edge_def::dest, find_pdom(), edge_def::flags, is_non_loop_exit_postdominating(), edge_def::src, and basic_block_def::succs.
Referenced by find_def_preds(), and find_predicates().
|
static |
Returns a bit mask holding the positions of arguments in PHI that have empty (or possibly empty) definitions.
References function::calls_setjmp, can_skip_redundant_opnd(), cfun, gimple_phi_arg_def(), gimple_phi_num_args(), function::has_nonlocal_label, and uninit_undefined_value_p().
Referenced by prune_uninit_phi_opnds_in_unrealizable_paths(), and warn_uninitialized_phi().
|
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().
|
static |
|
static |
Dumps the predicates (PREDS) for USESTMT.
References use_pred_info::cond, dump_file, use_pred_info::invert, and print_gimple_stmt().
Referenced by is_use_properly_guarded().
|
static |
Entry point to the late uninitialized warning pass.
References calculate_dominance_info(), CDI_DOMINATORS, CDI_POST_DOMINATORS, dump_file, dump_flags, free_dominance_info(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_phis(), gsi_stmt(), pointer_set_create(), pointer_set_destroy(), pointer_set_insert(), print_gimple_stmt(), timevar_pop(), timevar_push(), uninit_undefined_value_p(), virtual_operand_p(), vNULL, warn_uninitialized_phi(), warn_uninitialized_vars(), and worklist.
|
inlinestatic |
Find the closest postdominator of a specified BB, which is control equivalent to BB.
References CDI_DOMINATORS, dominated_by_p(), find_pdom(), and is_non_loop_exit_postdominating().
Referenced by find_predicates().
|
static |
For each use edge of PHI, computes all control dependence chains. The control dependence chains are then converted to an array of composite predicates pointed to by PREDS.
References collect_phi_def_edges(), compute_control_dep_chain(), convert_control_dep_chain_into_preds(), find_dom(), free(), gimple_bb(), pointer_set_create(), pointer_set_destroy(), edge_def::src, basic_block_def::succs, and vNULL.
Referenced by is_use_properly_guarded().
|
inlinestatic |
Find the immediate DOM of the specified basic block BLOCK.
References CDI_DOMINATORS, and get_immediate_dominator().
Referenced by find_def_preds().
|
static |
Returns true if PRED is common among all the predicate chains (PREDS) (and therefore can be factored out). NUM_PRED_CHAIN is the size of array PREDS.
References use_pred_info::cond, and use_pred_info::invert.
Referenced by use_pred_not_overlap_with_undef_path_pred().
|
inlinestatic |
Find the immediate postdominator PDOM of the specified basic block BLOCK.
References CDI_POST_DOMINATORS, and get_immediate_dominator().
Referenced by compute_control_dep_chain(), and find_control_equiv_block().
|
static |
Computes all control dependence chains for USE_BB. The control dependence chains are then converted to an array of composite predicates pointed to by PREDS. PHI_BB is the basic block of the phi whose result is used in USE_BB.
References CDI_DOMINATORS, compute_control_dep_chain(), convert_control_dep_chain_into_preds(), dominated_by_p(), find_control_equiv_block(), free(), and vNULL.
Referenced by is_use_properly_guarded().
|
static |
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 |
|
static |
Computes the 'normalized' conditional code with operand swapping and condition inversion.
References invert_tree_comparison(), and swap_tree_comparison().
Referenced by use_pred_not_overlap_with_undef_path_pred().
|
static |
Returns the first bit position (starting from LSB) in mask that is non zero. Returns -1 if the mask is empty.
|
inlinestatic |
Returns true if TC is AND or OR
Referenced by normalize_cond(), and normalize_cond_1().
|
static |
NORM_COND1 and NORM_COND2 are normalized logical AND expressions (formed by following UD chains not control dependence chains). The function returns true of domain of and expression NORM_COND1 is a subset of NORM_COND2's.
References norm_cond::conds, is_subset_of_any(), and len.
Referenced by is_norm_cond_subset_of().
|
static |
Returns true if the domain for condition COND1 is a subset of COND2. REVERSE is a flag. when it is true the function checks if COND1 is a superset of COND2. INVERT1 and INVERT2 are flags to indicate if COND1 and COND2 need to be inverted or not.
References gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), invert_tree_comparison(), is_gimple_constant(), is_value_included_in(), tcc_comparison, and tree_int_cst_equal().
Referenced by is_norm_cond_subset_of(), and is_subset_of_any().
|
static |
Returns true if the domain defined by one pred chain ONE_PRED is a subset of the domain of *PREDS. It returns false if ONE_PRED's domain is not a subset of any of the sub-domains of PREDS ( corresponding to each individual chains in it), even though it may be still be a subset of whole domain of PREDS which is the union (ORed) of all its subdomains. In other words, the result is conservative.
References is_pred_chain_subset_of().
Referenced by is_superset_of().
|
static |
Returns true if BB1 is postdominating BB2 and BB1 is not a loop exit bb. The loop exit bb check is simple and does not cover all cases.
References CDI_POST_DOMINATORS, dominated_by_p(), single_pred_p(), and single_succ_p().
Referenced by compute_control_dep_chain(), find_control_equiv_block(), and is_use_properly_guarded().
|
static |
Returns true of the domain if NORM_COND1 is a subset of that of NORM_COND2. Returns false if it can not be proved to be so.
References norm_cond::cond_code, norm_cond::conds, norm_cond::invert, is_and_set_subset_of(), is_gcond_subset_of(), is_or_set_subset_of(), and is_subset_of_any().
Referenced by is_pred_expr_subset_of().
|
static |
NORM_COND1 and NORM_COND2 are normalized logical/BIT OR expressions (formed by following UD chains not control dependence chains). The function returns true of domain of and expression NORM_COND1 is a subset of NORM_COND2's. The implementation is conservative, and it returns false if it the inclusion relationship may not hold.
References norm_cond::conds, is_subset_of_any(), and len.
Referenced by is_norm_cond_subset_of().
|
static |
Returns true if the domain of PRED1 is a subset of that of PRED2. Returns false if it can not be proved so.
References i1, i2, and is_pred_expr_subset_of().
Referenced by is_included_in().
|
static |
Returns true of the domain of single predicate expression EXPR1 is a subset of that of EXPR2. Returns false if it can not be proved.
References use_pred_info::cond, norm_cond::conds, gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), use_pred_info::invert, invert_tree_comparison(), is_norm_cond_subset_of(), and normalize_cond().
Referenced by is_pred_chain_subset_of().
|
static |
Returns true if the domain of the condition expression in COND is a subset of any of the sub-conditions of the normalized condtion NORM_COND. INVERT is a flag to indicate of the COND needs to be inverted. REVERSE is a flag. When it is true, the check is reversed -- it returns true if COND is a superset of any of the subconditions of NORM_COND.
References norm_cond::conds, is_gcond_subset_of(), and len.
Referenced by is_and_set_subset_of(), is_norm_cond_subset_of(), and is_or_set_subset_of().
|
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().
|
static |
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 |
Returns true if VAL falls in the range defined by BOUNDARY and CMPC, i.e. all values in the range satisfies (x CMPC BOUNDARY) == true.
References invert_tree_comparison(), and tree_int_cst_equal().
Referenced by is_gcond_subset_of(), and prune_uninit_phi_opnds_in_unrealizable_paths().
gimple_opt_pass* make_pass_late_warn_uninitialized | ( | ) |
|
static |
See normalize_cond_1 for details. INVERT is a flag to indicate if COND needs to be inverted or not.
References norm_cond::cond_code, norm_cond::conds, gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), integer_zerop(), norm_cond::invert, invert_tree_comparison(), is_and_or_or(), and normalize_cond_1().
Referenced by is_pred_expr_subset_of().
|
static |
Normalizes gimple condition COND. The normalization follows UD chains to form larger condition expression trees. NORM_COND holds the normalized result. COND_CODE is the logical opcode (AND or OR) of the normalized tree.
References norm_cond::cond_code, norm_cond::conds, gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), integer_zerop(), and is_and_or_or().
Referenced by normalize_cond().
|
static |
x OR (!x AND y) is equivalent to x OR y. This function normalizes x1 OR (!x1 AND x2) OR (!x1 AND !x2 AND x3) into x1 OR x2 OR x3. PREDS is the predicate chains, and N is the number of chains. Returns true if normalization happens.
References use_pred_info::cond, free(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), use_pred_info::invert, pred_chain_length_cmp(), and vNULL.
Referenced by is_use_properly_guarded().
|
static |
Comparison function used by qsort. It is used to sort predicate chains to allow predicate simplification.
References use_pred_info::cond, gimple_uid(), i1, i2, and use_pred_info::invert.
Referenced by normalize_preds().
|
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().
bool ssa_undefined_value_p | ( | ) |
Return true if T, an SSA_NAME, has an undefined value.
References gimple_nop_p(), and pointer_set_contains().
|
inlinestatic |
Like ssa_undefined_value_p, but don't return true if TREE_NO_WARNING is set on SSA_NAME_VAR.
References ssa_undefined_value_p().
Referenced by can_skip_redundant_opnd(), collect_phi_def_edges(), compute_uninit_opnds_pos(), and execute_late_warn_uninitialized().
|
static |
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().
|
static |
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().
|
static |
@verbatim Predicate aware uninitialized variable warning.
Copyright (C) 2001-2013 Free Software Foundation, Inc. Contributed by Xinliang David Li david xl@g oogle .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.