GCC Middle and Back End API Reference
tree-ssa-uninit.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "flags.h"
#include "tm_p.h"
#include "basic-block.h"
#include "function.h"
#include "gimple-pretty-print.h"
#include "bitmap.h"
#include "pointer-set.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "tree-ssa.h"
#include "tree-inline.h"
#include "hashtab.h"
#include "tree-pass.h"
#include "diagnostic-core.h"
Include dependency graph for tree-ssa-uninit.c:

Data Structures

struct  use_pred_info
struct  norm_cond

Macros

#define MASK_SET_BIT(mask, pos)   mask |= (1 << pos)
#define MASK_TEST_BIT(mask, pos)   (mask & (1 << pos))
#define MASK_EMPTY(mask)   (mask == 0)
#define MASK_FIRST_SET_BIT(mask)   get_mask_first_set_bit (mask)
#define MAX_NUM_CHAINS   8
#define MAX_CHAIN_LEN   5
#define MAX_POSTDOM_CHECK   8

Typedefs

typedef struct use_pred_infouse_pred_info_t
typedef struct norm_condnorm_cond_t

Functions

static int get_mask_first_set_bit ()
static bool has_undefined_value_p ()
static bool uninit_undefined_value_p (tree t)
static void warn_uninit (enum opt_code wc, tree t, tree expr, tree var, const char *gmsgid, void *data)
static unsigned int warn_uninitialized_vars ()
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_passmake_pass_late_warn_uninitialized ()
static unsigned int execute_early_warn_uninitialized ()
gimple_opt_passmake_pass_early_warn_uninitialized ()

Variables

static struct pointer_set_tpossibly_undefined_names = 0

Macro Definition Documentation

#define MASK_EMPTY (   mask)    (mask == 0)
#define MASK_FIRST_SET_BIT (   mask)    get_mask_first_set_bit (mask)
#define MASK_SET_BIT (   mask,
  pos 
)    mask |= (1 << pos)

Bit mask handling macros.

Referenced by compute_uninit_opnds_pos().

#define MASK_TEST_BIT (   mask,
  pos 
)    (mask & (1 << pos))
#define MAX_CHAIN_LEN   5
#define MAX_NUM_CHAINS   8
#define MAX_POSTDOM_CHECK   8

Typedef Documentation

typedef struct norm_cond * norm_cond_t
typedef struct use_pred_info * use_pred_info_t

Function Documentation

static bool can_skip_redundant_opnd ( )
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.

static void collect_phi_def_edges ( gimple  phi,
basic_block  cd_root,
vec< edge > *  edges,
struct pointer_set_t visited_phis 
)
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 dump_file, dump_flags, and print_gimple_stmt().

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

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.

 Could  use a set instead.   
     cycle detected.  
             Found a direct control dependence.   
             check path from next edge.   
         Now check if DEP_BB is indirectly control dependent on BB.   
static unsigned compute_uninit_opnds_pos ( )
static

Returns a bit mask holding the positions of arguments in PHI that have empty (or possibly empty) definitions.

Bail out for phi with too many args.

             Ignore SSA_NAMEs that appear on abnormal edges
             somewhere.   

References cfun, MASK_SET_BIT, and SSA_NAME_OCCURS_IN_ABNORMAL_PHI.

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.

 Now convert the control dep chain into a set
 of predicates.   
             Ignore EH edge. Can add assertion
             on the other edge's flag.   
         Skip if there is essentially one succesor.   
static void destroy_predicate_vecs ( size_t  n,
vec< use_pred_info_t > *  preds 
)
static

Destroys the predicate set *PREDS.

References TREE_CODE, TREE_TYPE, and TYPE_UNSIGNED.

static void dump_predicates ( gimple  usestmt,
size_t  num_preds,
vec< use_pred_info_t > *  preds,
const char *  msg 
)
static

Dumps the predicates (PREDS) for USESTMT.

do some dumping here:

static unsigned int execute_early_warn_uninitialized ( )
static

Currently, this pass runs always but execute_late_warn_uninitialized only runs with optimization. With 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".

 Post-dominator information can not be reliably updated. Free it
 after the use.   
static unsigned int execute_late_warn_uninitialized ( )
static

Entry point to the late uninitialized warning pass.

 Re-do the plain uninitialized variable check, as optimization may have
 straightened control flow.  Do this first so that we don't accidentally
 get a "may be" warning when we'd have seen an "is" warning later.   
 Initialize worklist   
       Don't look at virtual operands.   

References gate_warn_uninitialized().

static basic_block find_control_equiv_block ( )
inlinestatic

Find the closest postdominator of a specified BB, which is control equivalent to BB.

Skip the postdominating bb that is also loop exit.

static bool find_def_preds ( vec< use_pred_info_t > **  preds,
size_t *  num_preds,
gimple  phi 
)
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.

 First find the closest dominating bb to be
 the control dependence root   
     Free individual chain   
     Now update the newly added chains with
     the phi operand edge:   
static basic_block find_dom ( )
inlinestatic

Find the immediate DOM of the specified basic block BLOCK.

References CDI_POST_DOMINATORS, dominated_by_p(), single_pred_p(), and single_succ_p().

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

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.

trival case

         can relax the condition comparison to not
         use address comparison. However, the most common
         case is that multiple control dependent paths share
         a common path prefix, so address comparison should
         be ok.   

References BITMAP_ALLOC, bitmap_bit_p, bitmap_set_bit, gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), is_gimple_constant(), MASK_TEST_BIT, MIN, NULL, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, and TREE_CODE.

static basic_block find_pdom ( )
inlinestatic

Find the immediate postdominator PDOM of the specified basic block BLOCK.

References CDI_DOMINATORS, ENTRY_BLOCK_PTR, and get_immediate_dominator().

static bool find_predicates ( vec< use_pred_info_t > **  preds,
size_t *  num_preds,
basic_block  phi_bb,
basic_block  use_bb 
)
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.

First find the closest bb that is control equivalent to PHI_BB that also dominates USE_BB.

 Free individual chain   
static gimple find_uninit_use ( gimple  phi,
unsigned  uninit_opnds,
vec< gimple > *  worklist,
struct pointer_set_t added_to_worklist 
)
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.

Found one real use, return.

     Found a phi use that is not guarded,
     add the phi to the worklist.   

References dump_file, and print_gimple_stmt().

static bool gate_warn_uninitialized ( )
static
static enum tree_code get_cmp_code ( enum tree_code  orig_cmp_code,
bool  swap_cond,
bool  invert 
)
static

Computes the 'normalized' conditional code with operand swapping and condition inversion.

References invert_tree_comparison().

static int get_mask_first_set_bit ( )
static

Returns the first bit position (starting from LSB) in mask that is non zero. Returns -1 if the mask is empty.

static bool has_undefined_value_p ( )
static

Return true if T, an SSA_NAME, has an undefined value.

References SSA_NAME_VAR, and TREE_NO_WARNING.

Referenced by uninit_undefined_value_p().

static bool is_and_or_or ( )
inlinestatic

Returns true if TC is AND or OR

References normalize_cond_1(), and SSA_NAME_DEF_STMT.

static bool is_and_set_subset_of ( norm_cond_t  norm_cond1,
norm_cond_t  norm_cond2 
)
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, gcc_assert, norm_cond::invert, is_gcond_subset_of(), and is_subset_of_any().

Referenced by is_subset_of_any().

static bool is_gcond_subset_of ( gimple  cond1,
bool  invert1,
gimple  cond2,
bool  invert2,
bool  reverse 
)
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.

Take the short cut.

 Assuming const operands have been swapped to the
 rhs at this point of the analysis.   

Referenced by is_and_set_subset_of().

static bool is_included_in ( vec< use_pred_info_t one_pred,
vec< use_pred_info_t > *  preds,
size_t  n 
)
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 pred_chain_length_cmp(), and vNULL.

Referenced by is_pred_chain_subset_of().

static bool is_non_loop_exit_postdominating ( )
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.

static bool is_norm_cond_subset_of ( norm_cond_t  norm_cond1,
norm_cond_t  norm_cond2 
)
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.

     Both conditions are AND expressions.   
     NORM_COND1 is an AND expression, and NORM_COND2 is an OR
     expression. In this case, returns true if any subexpression
     of NORM_COND1 is a subset of any subexpression of NORM_COND2.   
 NORM_COND1 is an OR expression   
     Conservatively returns false if NORM_COND1 is non-decomposible
     and NORM_COND2 is an AND expression.   

References use_pred_info::cond, norm_cond::conds, gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), use_pred_info::invert, invert_tree_comparison(), and normalize_cond().

static bool is_or_set_subset_of ( norm_cond_t  norm_cond1,
norm_cond_t  norm_cond2 
)
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.

static bool is_pred_chain_subset_of ( vec< use_pred_info_t pred1,
vec< use_pred_info_t pred2 
)
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 is_included_in().

Referenced by is_pred_expr_subset_of().

static bool is_pred_expr_subset_of ( use_pred_info_t  expr1,
use_pred_info_t  expr2 
)
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.

 Fast path &ndash; match exactly   
 Normalize conditions. To keep NE_EXPR, do not invert
 with both need inversion.   
 Free memory   

References is_pred_chain_subset_of().

static bool is_subset_of_any ( gimple  cond,
bool  invert,
norm_cond_t  norm_cond,
bool  reverse 
)
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::cond_code, norm_cond::conds, and is_and_set_subset_of().

Referenced by is_and_set_subset_of().

static bool is_superset_of ( vec< use_pred_info_t > *  preds1,
size_t  n1,
vec< use_pred_info_t > *  preds2,
size_t  n2 
)
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.

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

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.

further prune the dead incoming phi edges.

References dump_file, dump_flags, gimple_bb(), gimple_phi_arg_edge(), is_gimple_debug(), PHI_ARG_INDEX_FROM_USE, pointer_set_create(), pointer_set_destroy(), pointer_set_insert(), print_gimple_stmt(), edge_def::src, and USE_STMT.

static bool is_value_included_in ( )
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.

Only handle integer constant here.

gimple_opt_pass* make_pass_early_warn_uninitialized ( )
gimple_opt_pass* make_pass_late_warn_uninitialized ( )
static void normalize_cond ( )
static

See normalize_cond_1 for details. INVERT is a flag to indicate if COND needs to be inverted or not.

Referenced by is_norm_cond_subset_of().

static void normalize_cond_1 ( gimple  cond,
norm_cond_t  norm_cond,
enum tree_code  cond_code 
)
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.

Referenced by is_and_or_or().

static bool normalize_preds ( )
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.

 First sort the chains in ascending order of lengths.   
        See if simplification x AND y OR x AND !y is possible.   
        Now merge the first two chains.   
 The loop extracts x1, x2, x3, etc from chains
 x1 OR (!x1 AND x2) OR (!x1 AND !x2 AND x3) OR ...   
         Check if nxj is !xj   
 Now normalize the pred chains using the extraced x1, x2, x3 etc.   
     A new chain.   
static int pred_chain_length_cmp ( )
static

Comparison function used by qsort. It is used to sort predicate chains to allow predicate simplification.

Allow predicates with similar prefix come together.

Referenced by is_included_in().

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.

Now recursively prune the uninitialized phi args.   
     Now check if the constant is in the guarded range.   


         Now that we know that this undefined edge is not
         pruned. If the operand is defined by another phi,
         we can further prune the incoming edges of that
         phi by checking the predicates of this operands.   
static bool uninit_undefined_value_p ( tree  t)
inlinestatic

Like has_undefined_value_p, but don't return true if TREE_NO_WARNING is set on SSA_NAME_VAR.

References has_undefined_value_p().

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

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 &ndash; 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.   

Find within the common prefix of multiple predicate chains a predicate that is a comparison of a flag variable against a constant.

 Now check all the uninit incoming edge has a constant flag value
 that is in conflict with the use guard/predicate.   
static void warn_uninit ( enum opt_code  wc,
tree  t,
tree  expr,
tree  var,
const char *  gmsgid,
void *  data 
)
static

Emit warnings for uninitialized variables. This is done in two passes.

The first pass notices real uses of SSA names with undefined values. Such uses are unconditionally uninitialized, and we can be certain that such a use is a mistake. This pass is run before most optimizations, so that we catch as many as we can.

The second pass follows PHI nodes to find uses that are potentially uninitialized. In this case we can't necessarily prove that the use is really uninitialized. This pass is run after most optimizations, so that we thread as many jumps and possible, and delete as much dead code as possible, in order to reduce false positives. We also look 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 LOCUS may contain a location or be null. WC is the warning code.

TREE_NO_WARNING either means we already warned, or the front end wishes to suppress the warning.

Referenced by warn_uninitialized_vars().

static void warn_uninitialized_phi ( gimple  phi,
vec< gimple > *  worklist,
struct pointer_set_t added_to_worklist 
)
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.

 Don't look at virtual operands.   
 Now check if we have any use of the value without proper guard.   
 All uses are properly guarded.   
static unsigned int warn_uninitialized_vars ( )
static
         We only do data flow with SSA_NAMEs, so that's all we
         can warn about.   
         For memory the only cheap thing we can do is see if we
         have a use of the default def of the virtual operand.
         ???  Note that at -O0 we do not have virtual operands.
         ???  Not so cheap would be to use the alias oracle via
         walk_aliased_vdefs, if we don't find any aliasing vdef
         warn as is-used-uninitialized, if we don't find an aliasing
         vdef that kills our use (stmt_kills_ref_p), warn as
         may-be-used-uninitialized.  But this walk is quadratic and
         so must be limited which means we would miss warning
         opportunities.   
             Do not warn if it can be initialized outside this function.   

References DECL_HARD_REGISTER, FOR_EACH_SSA_USE_OPERAND, get_base_address(), gimple_assign_rhs1(), gimple_assign_single_p(), gimple_vdef(), gimple_vuse(), gsi_stmt(), is_gimple_debug(), is_global_var(), SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VAR, SSA_OP_USE, TREE_CODE, USE_FROM_PTR, and warn_uninit().


Variable Documentation

struct pointer_set_t* possibly_undefined_names = 0
static

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.