GCC Middle and Back End API Reference
tree-ssa-strlen.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool is_strlen_related_p (tree, tree)
 
bool maybe_diag_stxncpy_trunc (gimple_stmt_iterator, tree, tree, pointer_query *=NULL)
 
tree set_strlen_range (tree, wide_int, wide_int, tree=NULL_TREE)
 
tree get_range (tree, gimple *, wide_int[2], class range_query *=NULL)
 
void get_range_strlen_dynamic (tree, gimple *, c_strlen_data *, pointer_query &)
 
gimpleuse_in_zero_equality (tree, bool=true)
 
bool handle_printf_call (gimple_stmt_iterator *, pointer_query &)
 

Function Documentation

◆ get_range()

tree get_range ( tree val,
gimple * stmt,
wide_int minmax[2],
range_query * rvals )
extern
Sets MINMAX to either the constant value or the range VAL is in
and returns either the constant value or VAL on success or null
when the range couldn't be determined.  Uses RVALS or CFUN for
range info, whichever is nonnull.   

References cfun, get_legacy_range(), get_range_query(), ggc_alloc(), NULL_TREE, range_query::range_of_expr(), wi::to_wide(), TREE_TYPE, and VR_RANGE.

Referenced by get_offset_range(), get_stridx(), known_lower(), strlen_pass::maybe_warn_overflow(), range_query::query_relation(), range_query::query_relation(), and dom_ranger::range_of_stmt().

◆ get_range_strlen_dynamic()

void get_range_strlen_dynamic ( tree src,
gimple * stmt,
c_strlen_data * pdata,
pointer_query & ptr_qry )
extern
Analogous to get_range_strlen but for dynamically created strings,
i.e., those created by calls to strcpy as opposed to just string
constants.
Try to obtain the range of the lengths of the string(s) referenced
by SRC, or the size of the largest array SRC refers to if the range
of lengths cannot be determined, and store all in *PDATA.  RVALS
points to the valuation engine used to calculate ranges.   

References build_all_ones_cst(), get_range_strlen_dynamic(), ggc_alloc(), size_type_node, ssize_int, and visited.

◆ handle_printf_call()

bool handle_printf_call ( gimple_stmt_iterator * gsi,
pointer_query & ptr_qry )
extern
APIs internal to strlen pass.  Defined in gimple-ssa-sprintf.cc.   
Determine if a GIMPLE call at *GSI is to one of the sprintf-like built-in
functions and if so, handle it.  Return true if the call is removed and
gsi_next should not be performed in the caller.   

References BUILT_IN_NORMAL, DECL_FUNCTION_CODE(), EXPR_LOC_OR_LOC, ggc_alloc(), gimple_call_arg(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_call_num_args(), gimple_location(), gsi_stmt(), HOST_WIDE_INT_M1U, HOST_WIDE_INT_MAX, integer_zerop(), irange::lower_bound(), NULL_TREE, POINTER_TYPE_P, range_query::range_of_expr(), pointer_query::rvals, suppress_warning(), TREE_CODE, tree_fits_uhwi_p(), TREE_INT_CST_LOW, tree_to_uhwi(), TREE_TYPE, UINT_MAX, vrange::undefined_p(), irange::upper_bound(), warning_at(), and wide_int_to_tree().

Referenced by strlen_pass::check_and_optimize_call().

◆ is_strlen_related_p()

bool is_strlen_related_p ( tree src,
tree len )
extern
Return true if LEN depends on a call to strlen(SRC) in an interesting
way.  LEN can either be an integer expression, or a pointer (to char).
When it is the latter (such as in recursive calls to self) it is
assumed to be the argument in some call to strlen() whose relationship
to SRC is being ascertained.   

References BUILT_IN_NORMAL, DECL_FUNCTION_CODE(), ggc_alloc(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_call_arg(), gimple_call_builtin_p(), gimple_call_fndecl(), INTEGRAL_TYPE_P, is_gimple_assign(), is_gimple_call(), is_strlen_related_p(), laststmt_struct::len, operand_equal_p(), SSA_NAME_DEF_STMT, TREE_CODE, TREE_TYPE, and valid_builtin_call().

Referenced by strlen_pass::handle_builtin_stxncpy_strncat(), is_strlen_related_p(), maybe_diag_stxncpy_trunc(), maybe_warn_nonstring_arg(), and strlen_pass::maybe_warn_overflow().

◆ maybe_diag_stxncpy_trunc()

bool maybe_diag_stxncpy_trunc ( gimple_stmt_iterator gsi,
tree src,
tree cnt,
pointer_query * ptr_qry )
extern
Called by handle_builtin_stxncpy_strncat and by
  gimple_fold_builtin_strncpy in gimple-fold.cc.
  Check to see if the specified bound is a) equal to the size of
  the destination DST and if so, b) if it's immediately followed by
  DST[CNT - 1] = '\0'.  If a) holds and b) does not, warn.  Otherwise,
  do nothing.  Return true if diagnostic has been issued.

  The purpose is to diagnose calls to strncpy and stpncpy that do
  not nul-terminate the copy while allowing for the idiom where
  such a call is immediately followed by setting the last element
  to nul, as in:
    char a[32];
    strncpy (a, s, sizeof a);
    a[sizeof a - 1] = '\0';

References cfun, compute_objsize(), DECL_FUNCTION_CODE(), EDGE_SUCC, get_addr_base_and_unit_offset(), get_attr_nonstring_decl(), get_legacy_range(), get_range_query(), get_range_strlen(), get_stridx(), get_strinfo(), wi::geu_p(), ggc_alloc(), gimple_assign_lhs(), gimple_bb(), gimple_call_arg(), gimple_call_fndecl(), gimple_call_lhs(), gimple_or_expr_nonartificial_location(), gsi_next_nondebug(), gsi_start_bb(), gsi_stmt(), wi::gtu_p(), integer_all_onesp(), is_gimple_assign(), is_gimple_debug(), is_strlen_related_p(), known_eq, wi::leu_p(), wi::ltu_p(), wi::neg_p(), NULL, NULL_TREE, operand_equal_p(), ptrdiff_type_node, r, wi::shwi(), single_succ_p(), ssa_ver_to_stridx, laststmt_struct::stmt, wi::to_wide(), TREE_CODE, TREE_OPERAND, TREE_TYPE, TYPE_MAX_VALUE, TYPE_PRECISION, VR_ANTI_RANGE, warning_at(), warning_n(), warning_suppressed_p(), and wi::zero().

Referenced by gimple_fold_builtin_strncpy(), and strlen_pass::handle_builtin_stxncpy_strncat().

◆ set_strlen_range()

tree set_strlen_range ( tree lhs,
wide_int min,
wide_int max,
tree bound )
extern
For an LHS that is an SSA_NAME that is the result of a strlen()
call, or when BOUND is non-null, of a strnlen() call, set LHS
range info to [0, min (MAX, BOUND)] when the range includes more
than one value and return LHS.  Otherwise, when the range
[MIN, MAX] is such that MIN == MAX, return the tree representation
of (MIN). The latter allows callers to fold suitable strnlen() calls
to constants.   

References cfun, wi::cmpu(), get_range_query(), ggc_alloc(), INTEGRAL_TYPE_P, wi::ltu_p(), wi::ne_p(), NULL_TREE, r, path_range_query::range_of_expr(), set_range_info(), size_type_node, wi::to_wide(), TREE_CODE, TREE_TYPE, and wide_int_to_tree().

Referenced by gimple_fold_builtin_strlen(), strlen_pass::handle_builtin_strlen(), and maybe_set_strlen_range().

◆ use_in_zero_equality()

gimple * use_in_zero_equality ( tree res,
bool exclusive )
extern
Return first such statement if RES is used in statements testing its
equality to zero, and null otherwise.  If EXCLUSIVE is true, return
nonnull if and only RES is used in such expressions exclusively and
in none other.   

References FOR_EACH_IMM_USE_FAST, ggc_alloc(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_cond_code(), gimple_cond_rhs(), integer_zerop(), is_gimple_debug(), NULL, TREE_CODE, TREE_OPERAND, and USE_STMT.

Referenced by strlen_pass::handle_builtin_memcmp(), strlen_pass::handle_builtin_string_cmp(), maybe_warn_pointless_strcmp(), and simplify_builtin_call().