GCC Middle and Back End API Reference
|
Public Types | |
enum | reachability { ALL_BLOCKS , REACHABLE_BLOCKS , REACHABLE_BLOCKS_PRESERVING_FLAGS } |
Public Member Functions | |
strlen_pass (function *fun, cdi_direction direction) | |
~strlen_pass () | |
edge | before_dom_children (basic_block) final override |
void | after_dom_children (basic_block) final override |
bool | check_and_optimize_stmt (bool *cleanup_eh) |
bool | check_and_optimize_call (bool *zero_write) |
bool | handle_assign (tree lhs, bool *zero_write) |
bool | handle_store (bool *zero_write) |
void | handle_pointer_plus () |
void | handle_builtin_strlen () |
void | handle_builtin_strchr () |
void | handle_builtin_strcpy (built_in_function) |
void | handle_integral_assign (bool *cleanup_eh) |
void | handle_builtin_stxncpy_strncat (bool append_p) |
void | handle_builtin_memcpy (built_in_function bcode) |
void | handle_builtin_strcat (built_in_function bcode) |
void | handle_builtin_strncat (built_in_function) |
bool | handle_builtin_memset (bool *zero_write) |
bool | handle_builtin_memcmp () |
bool | handle_builtin_string_cmp () |
void | handle_alloc_call (built_in_function) |
void | maybe_warn_overflow (gimple *stmt, bool call_lhs, tree len, strinfo *si=NULL, bool plus_one=false, bool rawmem=false) |
void | maybe_warn_overflow (gimple *stmt, bool call_lhs, unsigned HOST_WIDE_INT len, strinfo *si=NULL, bool plus_one=false, bool rawmem=false) |
void | adjust_last_stmt (strinfo *si, gimple *stmt, bool is_strcat) |
tree | strxcmp_eqz_result (gimple *stmt, tree arg1, int idx1, tree arg2, int idx2, unsigned HOST_WIDE_INT bound, unsigned HOST_WIDE_INT len[2], unsigned HOST_WIDE_INT *psize) |
bool | count_nonzero_bytes (tree expr_or_type, gimple *stmt, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul) |
bool | count_nonzero_bytes (tree exp, tree vuse, gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul, ssa_name_limit_t &snlim) |
bool | count_nonzero_bytes_addr (tree exp, tree vuse, gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul, ssa_name_limit_t &snlim) |
bool | get_len_or_size (gimple *stmt, tree arg, int idx, unsigned HOST_WIDE_INT lenrng[2], unsigned HOST_WIDE_INT *size, bool *nulterm) |
void | walk (basic_block) |
Data Fields | |
pointer_query | ptr_qry |
gimple_stmt_iterator | m_gsi |
bool | m_cleanup_cfg |
Static Public Attributes | |
static const edge | STOP = (edge)-1 |
Private Member Functions | |
bool | bb_reachable (struct function *, basic_block) |
void | propagate_unreachable_to_edges (basic_block, FILE *, dump_flags_t) |
Private Attributes | |
enum cdi_direction | m_dom_direction: 2 |
enum reachability | m_reachability: 2 |
bool | m_user_bb_to_rpo |
basic_block | m_unreachable_dom |
int * | m_bb_to_rpo |
|
inherited |
|
inline |
strlen_pass::~strlen_pass | ( | ) |
Release pointer_query cache.
References pointer_query::flush_cache(), and ptr_qry.
If the last .MEM setter statement before STMT is memcpy (x, y, strlen (y) + 1), the only .MEM use of it is STMT and STMT is known to overwrite x[strlen (x)], adjust the last memcpy to just memcpy (x, y, strlen (y)). SI must be the zero length strinfo.
References cfun, compute_objsize(), DECL_FUNCTION_CODE(), strinfo::first, gcc_assert, get_next_strinfo(), get_strinfo(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_call_arg(), gimple_call_fndecl(), gimple_call_set_arg(), gimple_vuse(), gsi_for_stmt(), gsi_remove(), has_single_use(), integer_onep(), integer_zerop(), is_gimple_assign(), last, laststmt, laststmt_struct::len, NULL, NULL_TREE, ptr_qry, release_defs(), si, SSA_NAME_DEF_STMT, laststmt_struct::stmt, stmt_could_throw_p(), laststmt_struct::stridx, TREE_CODE, tree_fits_uhwi_p(), tree_int_cst_lt(), tree_to_uhwi(), unlink_stmt_vdef(), update_stmt(), valid_builtin_call(), verify_related_strinfos(), and zero_length_string_p().
Referenced by handle_builtin_memcpy(), handle_builtin_strcat(), handle_builtin_strcpy(), and handle_store().
|
finaloverridevirtual |
Callback for walk_dominator_tree. Free strinfo vector if it is owned by the current bb, clear bb->aux.
Reimplemented from dom_walker.
References basic_block_def::aux, free_strinfo(), i, NULL, si, stridx_to_strinfo, vec_free(), vec_safe_iterate(), and vec_safe_length().
|
privateinherited |
Return TRUE if BB is reachable, false otherwise.
References dom_walker::ALL_BLOCKS, CDI_DOMINATORS, dominated_by_p(), ENTRY_BLOCK_PTR_FOR_FN, FOR_EACH_EDGE, dom_walker::m_reachability, dom_walker::m_unreachable_dom, and basic_block_def::preds.
Referenced by dom_walker::walk().
|
finaloverridevirtual |
Callback for walk_dominator_tree. Attempt to optimize various string ops by remembering string lengths pointed by pointer SSA_NAMEs.
Reimplemented from dom_walker.
References basic_block_def::aux, BITMAP_ALLOC, BITMAP_FREE, CDI_DOMINATORS, check_and_optimize_stmt(), pointer_query::depth, do_invalidate(), free_strinfo(), get_immediate_dominator(), get_stridx(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), gimple_purge_dead_eh_edges(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_start_phis(), i, m_cleanup_cfg, m_gsi, NULL, POINTER_TYPE_P, ptr_qry, si, SSA_NAME_VERSION, ssa_ver_to_stridx, stridx_to_strinfo, strinfo_shared(), TREE_TYPE, vec_safe_iterate(), vec_safe_length(), virtual_operand_p(), and visited.
Check the built-in call at GSI for validity and optimize it. Uses RVALS to determine range information. Return true to let the caller advance *GSI to the next statement in the basic block and false otherwise.
References BUILT_IN_NORMAL, DECL_FUNCTION_CODE(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_call_fntype(), gimple_call_lhs(), gsi_stmt(), handle_alloc_call(), handle_assign(), handle_builtin_memcmp(), handle_builtin_memcpy(), handle_builtin_memset(), handle_builtin_strcat(), handle_builtin_strchr(), handle_builtin_strcpy(), handle_builtin_string_cmp(), handle_builtin_strlen(), handle_builtin_strncat(), handle_builtin_stxncpy_strncat(), handle_printf_call(), lookup_attribute(), m_gsi, ptr_qry, strlen_optimize, TYPE_ATTRIBUTES, and valid_builtin_call().
Referenced by check_and_optimize_stmt().
Attempt to check for validity of the performed access a single statement at *GSI using string length knowledge, and to optimize it. If the given basic block needs clean-up of EH, CLEANUP_EH is set to true. Return true to let the caller advance *GSI to the next statement in the basic block and false otherwise.
References check_and_optimize_call(), dyn_cast(), fold_strstr_to_strncmp(), get_stridx(), gimple_assign_cast_p(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs_code(), gimple_assign_single_p(), gimple_clobber_p(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), gimple_vdef(), gsi_stmt(), handle_assign(), handle_integral_assign(), handle_pointer_plus(), INTEGRAL_TYPE_P, is_gimple_assign(), is_gimple_call(), m_gsi, maybe_invalidate(), POINTER_TYPE_P, SSA_NAME_VERSION, ssa_ver_to_stridx, strlen_optimize, TREE_CODE, TREE_SIDE_EFFECTS, and TREE_TYPE.
Referenced by before_dom_children().
bool strlen_pass::count_nonzero_bytes | ( | tree | exp, |
tree | vuse, | ||
gimple * | stmt, | ||
unsigned HOST_WIDE_INT | offset, | ||
unsigned HOST_WIDE_INT | nbytes, | ||
unsigned | lenrange[3], | ||
bool * | nulterm, | ||
bool * | allnul, | ||
bool * | allnonnul, | ||
ssa_name_limit_t & | snlim ) |
Recursively determine the minimum and maximum number of leading nonzero bytes in the representation of EXP at memory state VUSE and set LENRANGE[0] and LENRANGE[1] to each. Sets LENRANGE[2] to the total size of the access (which may be less than LENRANGE[1] when what's being referenced by EXP is a pointer rather than an array). Sets *NULTERM if the representation contains a zero byte, sets *ALLNUL if all the bytes are zero, and *ALLNONNUL is all are nonzero. OFFSET and NBYTES are the offset into the representation and the size of the access to it determined from an ADDR_EXPR (i.e., a pointer) or MEM_REF or zero for other expressions. Uses RVALS to determine range information. Avoids recursing deeper than the limits in SNLIM allow. Returns true on success and false otherwise.
References build_int_cst(), CHAR_BIT, char_type_node, CONSTRUCTOR_ELT, CONSTRUCTOR_ELTS, CONSTRUCTOR_NELTS, count_nonzero_bytes(), count_nonzero_bytes_addr(), ctor_for_folding(), DECL_P, error_mark_node, exp(), FOR_EACH_CONSTRUCTOR_ELT, g, gimple_assign_rhs1(), gimple_assign_single_p(), gimple_phi_arg_def(), gimple_phi_num_args(), i, INT_MAX, int_size_in_bytes(), native_encode_expr(), ssa_name_limit_t::next_phi(), nonzero_bytes_for_type(), NULL, offset, SSA_NAME_DEF_STMT, TREE_CODE, tree_expr_nonzero_p(), tree_fits_uhwi_p(), TREE_OPERAND, TREE_STRING_LENGTH, TREE_STRING_POINTER, tree_to_uhwi(), TREE_TYPE, TYPE_MODE, TYPE_PRECISION, TYPE_SIZE_UNIT, VAR_P, and VECTOR_TYPE_P.
bool strlen_pass::count_nonzero_bytes | ( | tree | expr_or_type, |
gimple * | stmt, | ||
unsigned | lenrange[3], | ||
bool * | nulterm, | ||
bool * | allnul, | ||
bool * | allnonnul ) |
Same as above except with an implicit SSA_NAME limit. When EXPR_OR_TYPE is a type rather than an expression use its size to compute the range. RVALS is used to determine ranges of dynamically computed string lengths (the results of strlen).
References count_nonzero_bytes(), gimple_vuse(), nonzero_bytes_for_type(), and TYPE_P.
Referenced by count_nonzero_bytes(), count_nonzero_bytes(), count_nonzero_bytes_addr(), handle_integral_assign(), and handle_store().
bool strlen_pass::count_nonzero_bytes_addr | ( | tree | exp, |
tree | vuse, | ||
gimple * | stmt, | ||
unsigned HOST_WIDE_INT | offset, | ||
unsigned HOST_WIDE_INT | nbytes, | ||
unsigned | lenrange[3], | ||
bool * | nulterm, | ||
bool * | allnul, | ||
bool * | allnonnul, | ||
ssa_name_limit_t & | snlim ) |
Like count_nonzero_bytes, but instead of counting bytes in EXP, count bytes that are pointed to by EXP, which should be a pointer.
References count_nonzero_bytes(), count_nonzero_bytes_addr(), exp(), g, get_stridx(), get_strinfo(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_vuse(), i, irange::lower_bound(), ssa_name_limit_t::next_phi(), offset, ptr_qry, range_query::range_of_expr(), pointer_query::rvals, si, SSA_NAME_DEF_STMT, generic_wide_int< storage >::to_uhwi(), TREE_CODE, tree_fits_shwi_p(), TREE_OPERAND, tree_to_shwi(), vrange::undefined_p(), irange::upper_bound(), and vrange::varying_p().
Referenced by count_nonzero_bytes(), and count_nonzero_bytes_addr().
bool strlen_pass::get_len_or_size | ( | gimple * | stmt, |
tree | arg, | ||
int | idx, | ||
unsigned HOST_WIDE_INT | lenrng[2], | ||
unsigned HOST_WIDE_INT * | size, | ||
bool * | nulterm ) |
Given strinfo IDX for ARG, sets LENRNG[] to the range of lengths of the string(s) referenced by ARG if it can be determined. If the length cannot be determined, sets *SIZE to the size of the array the string is stored in, if any. If no such array is known, sets *SIZE to -1. When the strings are nul-terminated sets *NULTERM to true, otherwise to false. When nonnull uses RVALS to determine range information. Returns true on success.
References cfun, get_range_query(), get_range_strlen_dynamic(), get_strinfo(), HOST_WIDE_INT_M1U, HOST_WIDE_INT_MAX, integer_all_onesp(), max_object_size(), c_strlen_data::maxbound, c_strlen_data::maxlen, c_strlen_data::minlen, NULL, ptr_qry, r, si, TREE_CODE, tree_fits_uhwi_p(), and tree_to_uhwi().
Referenced by handle_builtin_string_cmp(), and strxcmp_eqz_result().
void strlen_pass::handle_alloc_call | ( | built_in_function | bcode | ) |
Handle a call to an allocation function like alloca, malloc or calloc, or an ordinary allocation function declared with attribute alloc_size.
References build_int_cst(), gcc_assert, get_stridx(), gimple_call_lhs(), gsi_stmt(), m_gsi, new_stridx(), new_strinfo(), NULL_TREE, set_strinfo(), si, and size_type_node.
Referenced by check_and_optimize_call().
Handle assignment statement at *GSI to LHS. Set *ZERO_WRITE if the assignment stores all zero bytes.
References handle_store(), i, is_char_type(), TREE_CODE, TREE_OPERAND, and TREE_TYPE.
Referenced by check_and_optimize_call(), and check_and_optimize_stmt().
bool strlen_pass::handle_builtin_memcmp | ( | ) |
Handle a call to memcmp. We try to handle small comparisons by converting them to load and compare, and replacing the call to memcmp with a __builtin_memcmp_eq call where possible. return true when call is transformed, return false otherwise.
References as_a(), boolean_type_node, build2_loc(), build_int_cst(), build_nonstandard_integer_type(), build_pointer_type_for_mode(), builtin_decl_explicit(), char_type_node, CHAR_TYPE_SIZE, fold_build2_loc(), fold_const_aggregate_ref(), fold_convert_loc(), gcc_assert, GET_MODE_BITSIZE(), GET_MODE_SIZE(), get_pointer_alignment(), gimple_call_arg(), gimple_call_lhs(), gimple_call_set_fndecl(), gimple_location(), gimplify_and_update_call_from_tree(), gsi_stmt(), int_mode_for_size(), known_eq, m_gsi, MIN, pow2p_hwi(), ptr_mode, targetm, tree_fits_uhwi_p(), tree_to_uhwi(), TREE_TYPE, type(), TYPE_MODE, use_in_zero_equality(), and word_mode.
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_memcpy | ( | built_in_function | bcode | ) |
Handle a memcpy-like ({mem{,p}cpy,__mem{,p}cpy_chk}) call. If strlen of the second argument is known and length of the third argument is that plus one, strlen of the first argument is the same after this call. Uses RVALS to determine range information.
References adjust_last_stmt(), adjust_related_strinfos(), build_int_cst(), strinfo::dont_invalidate, strinfo::endptr, find_equal_ptrs(), fold_build2_loc(), fold_convert_loc(), strinfo::full_string_p, gcc_unreachable, get_stridx(), get_strinfo(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_call_arg(), gimple_call_lhs(), gimple_location(), gsi_stmt(), strinfo::idx, integer_onep(), integer_zerop(), is_gimple_assign(), laststmt, laststmt_struct::len, m_gsi, maybe_warn_overflow(), MIN, new_stridx(), new_strinfo(), strinfo::next, strinfo::nonzero_chars, NULL, NULL_TREE, strinfo::prev, set_strinfo(), si, size_type_node, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, ssa_ver_to_stridx, laststmt_struct::stmt, strinfo::stmt, laststmt_struct::stridx, TREE_CODE, tree_fits_uhwi_p(), tree_int_cst_le(), tree_to_uhwi(), TREE_TYPE, unshare_strinfo(), and strinfo::writable.
Referenced by check_and_optimize_call().
Handle a call to memset. After a call to calloc, memset(,0,) is unnecessary. memset(malloc(n),0,n) is calloc(n,1). return true when the call is transformed, false otherwise. When nonnull uses RVALS to determine range information.
References strinfo::alloc, build_int_cst(), build_one_cst(), builtin_decl_implicit(), CHAR_TYPE_SIZE, DECL_FUNCTION_CODE(), strinfo::dont_invalidate, find_equal_ptrs(), fold_convert, strinfo::full_string_p, get_stridx(), get_strinfo(), gimple_build_assign(), gimple_call_arg(), gimple_call_fndecl(), gimple_call_lhs(), gsi_for_stmt(), gsi_remove(), gsi_replace(), gsi_stmt(), HOST_WIDE_INT_1U, integer_zerop(), is_gimple_call(), m_gsi, maybe_warn_overflow(), new_stridx(), new_strinfo(), strinfo::nonzero_chars, NULL, operand_equal_p(), ptr_qry, release_defs(), pointer_query::rvals, set_strinfo(), size_type_node, strinfo::stmt, wi::to_wide(), TREE_CODE, unlink_stmt_vdef(), update_gimple_call(), valid_builtin_call(), and strinfo::writable.
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_strcat | ( | built_in_function | bcode | ) |
Handle a strcat-like ({strcat,__strcat_chk}) call. If strlen of the second argument is known, strlen of the first argument is increased by the length of the second argument. Furthermore, attempt to convert it to memcpy/strcpy if the length of the first argument is known.
References adjust_last_stmt(), adjust_related_strinfos(), build_int_cst(), builtin_decl_explicit(), builtin_decl_implicit(), builtin_decl_implicit_p(), check_bounds_or_overlap(), strinfo::dont_invalidate, dump_file, dump_flags, strinfo::endptr, find_equal_ptrs(), fold_build2, fold_build2_loc(), fold_convert_loc(), force_gimple_operand_gsi(), strinfo::full_string_p, gcc_assert, gcc_unreachable, get_stridx(), get_strinfo(), get_string_length(), gimple_call_arg(), gimple_call_lhs(), gimple_location(), GSI_SAME_STMT, gsi_stmt(), strinfo::idx, laststmt, laststmt_struct::len, m_gsi, new_stridx(), new_strinfo(), strinfo::next, no_warning, strinfo::nonzero_chars, NULL, NULL_TREE, operand_equal_p(), print_gimple_stmt(), set_strinfo(), si, size_type_node, size_zero_node, sizetype, laststmt_struct::stmt, strinfo::stmt, laststmt_struct::stridx, suppress_warning(), TDF_DETAILS, TDF_SLIM, TREE_CHAIN, TREE_TYPE, TREE_VALUE, type(), TYPE_ARG_TYPES, unshare_expr(), unshare_strinfo(), update_gimple_call(), update_stmt(), and strinfo::writable.
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_strchr | ( | ) |
Handle a strchr call. If strlen of the first argument is known, replace the strchr (x, 0) call with the endptr or x + strlen, otherwise remember that lhs of the call is endptr and strlen of the argument is endptr - x.
References build_int_cst(), check_nul_terminated_array(), dump_file, dump_flags, find_equal_ptrs(), fold_build2_loc(), fold_convert_loc(), get_stridx(), get_strinfo(), get_string_length(), gimple_call_arg(), gimple_call_lhs(), gimple_location(), gimplify_and_update_call_from_tree(), gsi_stmt(), integer_zerop(), m_gsi, new_stridx(), new_strinfo(), NULL, NULL_TREE, print_gimple_stmt(), set_strinfo(), si, size_type_node, sizetype, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, TDF_DETAILS, TDF_SLIM, TREE_CODE, TREE_TYPE, unshare_expr(), unshare_strinfo(), update_stmt(), useless_type_conversion_p(), and zero_length_string().
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_strcpy | ( | built_in_function | bcode | ) |
Handle a strcpy-like ({st{r,p}cpy,__st{r,p}cpy_chk}) call. If strlen of the second argument is known, strlen of the first argument is the same after this call. Furthermore, attempt to convert it to memcpy. Uses RVALS to determine range information.
References adjust_last_stmt(), adjust_related_strinfos(), build_int_cst(), builtin_decl_explicit(), builtin_decl_implicit(), builtin_decl_implicit_p(), check_bounds_or_overlap(), strinfo::dont_invalidate, dump_file, dump_flags, strinfo::endptr, find_equal_ptrs(), fold_build2, fold_build2_loc(), fold_convert_loc(), force_gimple_operand_gsi(), strinfo::full_string_p, gcc_unreachable, get_stridx(), get_strinfo(), get_string_length(), gimple_call_arg(), gimple_call_lhs(), gimple_call_num_args(), gimple_location(), GSI_SAME_STMT, gsi_stmt(), strinfo::idx, integer_zerop(), laststmt, laststmt_struct::len, m_gsi, maybe_warn_overflow(), new_stridx(), new_strinfo(), strinfo::next, no_warning, strinfo::nonzero_chars, NULL, NULL_TREE, strinfo::prev, print_gimple_stmt(), strinfo::ptr, set_strinfo(), si, size_type_node, SSA_NAME_VERSION, ssa_ver_to_stridx, laststmt_struct::stmt, strinfo::stmt, laststmt_struct::stridx, suppress_warning(), TDF_DETAILS, TDF_SLIM, TREE_CHAIN, TREE_CODE, TREE_TYPE, TREE_VALUE, type(), TYPE_ARG_TYPES, unshare_expr(), unshare_strinfo(), update_gimple_call(), update_stmt(), verify_related_strinfos(), strinfo::writable, and zero_length_string().
Referenced by check_and_optimize_call().
bool strlen_pass::handle_builtin_string_cmp | ( | ) |
Optimize a call to strcmp or strncmp either by folding it to a constant when possible or by transforming the latter to the former. Warn about calls where the length of one argument is greater than the size of the array to which the other argument points if the latter's length is not known. Return true when the call has been transformed into another and false otherwise.
References as_a(), build_int_cst(), builtin_decl_implicit(), check_nul_terminated_array(), get_len_or_size(), get_stridx(), gimple_call_arg(), gimple_call_lhs(), gimple_call_num_args(), gsi_stmt(), HOST_WIDE_INT_M1U, HOST_WIDE_INT_MAX, integer_zero_node, integer_zerop(), m_gsi, maybe_warn_pointless_strcmp(), MIN, NULL_TREE, replace_call_with_value(), irange::set_nonzero(), set_range_info(), size_type_node, strxcmp_eqz_result(), tree_fits_shwi_p(), tree_to_shwi(), TREE_TYPE, update_gimple_call(), and use_in_zero_equality().
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_strlen | ( | ) |
Handle a strlen call. If strlen of the argument is known, replace the strlen call with the known value, otherwise remember that strlen of the argument is stored in the lhs SSA_NAME.
References adjust_related_strinfos(), build_int_cst(), DECL_FUNCTION_CODE(), dump_file, dump_flags, find_equal_ptrs(), fold_build2_loc(), fold_convert_loc(), gcc_assert, get_stridx(), get_strinfo(), get_string_length(), gimple_call_arg(), gimple_call_fndecl(), gimple_call_lhs(), gimple_location(), gimplify_and_update_call_from_tree(), gsi_stmt(), wi::gtu_p(), integer_zerop(), m_gsi, maybe_set_strlen_range(), new_stridx(), new_strinfo(), NULL, NULL_TREE, print_gimple_stmt(), ptrdiff_type_node, set_strinfo(), set_strlen_range(), si, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, strlen_to_stridx, TDF_DETAILS, TDF_SLIM, wi::to_wide(), TREE_CODE, tree_int_cst_le(), tree_int_cst_lt(), TREE_TYPE, TYPE_MAX_VALUE, unshare_expr(), unshare_strinfo(), update_stmt(), and useless_type_conversion_p().
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_strncat | ( | built_in_function | ) |
Check the size argument to the built-in forms of stpncpy and strncpy for out-of-bounds offsets or overlapping access, and to see if the size argument is derived from a call to strlen() on the source argument, and if so, issue an appropriate warning.
References handle_builtin_stxncpy_strncat().
Referenced by check_and_optimize_call().
void strlen_pass::handle_builtin_stxncpy_strncat | ( | bool | append_p | ) |
Check the arguments to the built-in forms of stpncpy, strncpy, and strncat, for out-of-bounds offsets or overlapping access, and to see if the size is derived from calling strlen() on the source argument, and if so, issue the appropriate warning. APPEND_P is true for strncat.
References build_int_cst(), check_bounds_or_overlap(), fold_build2, strinfo::full_string_p, get_stridx(), get_strinfo(), gimple_call_alloc_size(), gimple_call_arg(), gimple_call_fndecl(), gimple_or_expr_nonartificial_location(), gsi_stmt(), inform(), is_strlen_related_p(), m_gsi, maybe_diag_stxncpy_trunc(), no_warning, strinfo::nonzero_chars, NULL, NULL_TREE, strinfo::ptr, SSA_NAME_DEF_STMT, strlen_to_stridx, suppress_warning(), TREE_CODE, TREE_TYPE, UNKNOWN_LOCATION, and warning_at().
Referenced by check_and_optimize_call(), and handle_builtin_strncat().
void strlen_pass::handle_integral_assign | ( | bool * | cleanup_eh | ) |
Handle an assignment statement at *GSI to a LHS of integral type. If GSI's basic block needs clean-up of EH, set *CLEANUP_EH to true.
References build_int_cst(), cfun, char_type_node, count_nonzero_bytes(), dump_file, dump_flags, fold_strstr_to_strncmp(), get_addr_stridx(), get_range_query(), get_stridx(), get_strinfo(), gimple_assign_lhs(), gimple_assign_load_p(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_set_rhs_from_tree(), gimple_has_volatile_ops(), gimple_set_vuse(), gsi_stmt(), integer_zero_node, m_gsi, maybe_clean_or_replace_eh_stmt(), new_stridx(), new_strinfo(), NULL_TREE, print_gimple_stmt(), r, set_range_info(), set_strinfo(), si, sizetype, strlen_to_stridx, TDF_DETAILS, TDF_SLIM, wi::to_widest(), TREE_CODE, TREE_OPERAND, TREE_TYPE, TYPE_MODE, TYPE_PRECISION, UINT_MAX, and update_stmt().
Referenced by check_and_optimize_stmt().
void strlen_pass::handle_pointer_plus | ( | ) |
Handle a POINTER_PLUS_EXPR statement. For p = "abcd" + 2; compute associated length, or if p = q + off is pointing to a '\0' character of a string, call zero_length_string on it.
References strinfo::endptr, gcc_assert, get_stridx(), get_strinfo(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_set_rhs_with_ops(), gimple_assign_single_p(), gsi_stmt(), m_gsi, NULL, NULL_TREE, operand_equal_p(), si, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, ssa_ver_to_stridx, TREE_CODE, tree_fits_uhwi_p(), tree_to_uhwi(), TREE_TYPE, update_stmt(), useless_type_conversion_p(), and zero_length_string().
Referenced by check_and_optimize_stmt().
Handle a single or multibyte store other than by a built-in function, either via a single character assignment or by multi-byte assignment either via MEM_REF or via a type other than char (such as in '*(int*)a = 12345'). Return true to let the caller advance *GSI to the next statement in the basic block and false otherwise.
References a, adjust_last_stmt(), adjust_related_strinfos(), build_fold_addr_expr, build_int_cst(), cfun, compare_nonzero_chars(), count_nonzero_bytes(), fold_build2_loc(), gcc_assert, get_addr_stridx(), get_stridx(), get_strinfo(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_call_lhs(), gimple_location(), gsi_next(), gsi_remove(), gsi_stmt(), HOST_WIDE_INT_M1U, initializer_zerop(), int_size_in_bytes(), is_gimple_assign(), is_gimple_call(), laststmt, laststmt_struct::len, m_gsi, maybe_warn_overflow(), new_addr_stridx(), new_stridx(), new_strinfo(), NULL, NULL_TREE, offset, ptr_qry, release_defs(), pointer_query::rvals, set_strinfo(), si, size_type_node, size_zero_node, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, laststmt_struct::stmt, stmt_could_throw_p(), laststmt_struct::stridx, TREE_CODE, tree_fits_uhwi_p(), TREE_OPERAND, tree_to_uhwi(), TREE_TYPE, UINT_MAX, unlink_stmt_vdef(), and unshare_strinfo().
Referenced by handle_assign().
void strlen_pass::maybe_warn_overflow | ( | gimple * | stmt, |
bool | call_lhs, | ||
tree | len, | ||
strinfo * | si = NULL, | ||
bool | plus_one = false, | ||
bool | rawmem = false ) |
Diagnose buffer overflow by a STMT writing LEN + PLUS_ONE bytes, either into a region allocated for the object SI when non-null, or into an object designated by the LHS of STMT otherwise. For a call STMT, when CALL_LHS is set use its left hand side as the destination, otherwise use argument zero. When nonnull uses RVALS to determine range information. RAWMEM may be set by memcpy and other raw memory functions to allow accesses across subobject boundaries.
References access_write_only, BUILT_IN_NORMAL, compute_objsize(), gcc_assert, get_range(), gimple_assign_lhs(), gimple_call_arg(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_call_lhs(), gimple_or_expr_nonartificial_location(), access_ref::inform_access(), is_gimple_assign(), is_gimple_call(), is_strlen_related_p(), wi::leu_p(), max_object_size(), NULL_TREE, access_ref::offrng, ptr_qry, pointer_query::rvals, si, SIGNED, access_ref::size_remaining(), access_ref::sizrng, suppress_warning(), wi::to_offset(), UNSIGNED, warning_at(), warning_n(), and warning_suppressed_p().
Referenced by handle_builtin_memcpy(), handle_builtin_memset(), handle_builtin_strcpy(), handle_store(), and maybe_warn_overflow().
void strlen_pass::maybe_warn_overflow | ( | gimple * | stmt, |
bool | call_lhs, | ||
unsigned HOST_WIDE_INT | len, | ||
strinfo * | si = NULL, | ||
bool | plus_one = false, | ||
bool | rawmem = false ) |
Convenience wrapper for the above.
References build_int_cst(), maybe_warn_overflow(), si, and size_type_node.
|
privateinherited |
BB has been determined to be unreachable. Propagate that property to incoming and outgoing edges of BB as appropriate.
References CDI_DOMINATORS, dominated_by_p(), dump_file, dump_flags, FOR_EACH_EDGE, basic_block_def::index, dom_walker::m_unreachable_dom, basic_block_def::preds, basic_block_def::succs, and TDF_DETAILS.
Referenced by dom_walker::walk().
tree strlen_pass::strxcmp_eqz_result | ( | gimple * | stmt, |
tree | arg1, | ||
int | idx1, | ||
tree | arg2, | ||
int | idx2, | ||
unsigned HOST_WIDE_INT | bound, | ||
unsigned HOST_WIDE_INT | len[2], | ||
unsigned HOST_WIDE_INT * | psize ) |
If IDX1 and IDX2 refer to strings A and B of unequal lengths, return the result of 0 == strncmp (A, B, BOUND) (which is the same as strcmp for a sufficiently large BOUND). If the result is based on the length of one string being greater than the longest string that would fit in the array pointer to by the argument, set *PLEN and *PSIZE to the corresponding length (or its complement when the string is known to be at least as long and need not be nul-terminated) and size. Otherwise return null.
References get_len_or_size(), HOST_WIDE_INT_M1U, HOST_WIDE_INT_MAX, integer_one_node, integer_zero_node, and NULL_TREE.
Referenced by handle_builtin_string_cmp().
|
inherited |
Recursively walk the dominator tree. BB is the basic block we are currently visiting.
References dom_walker::after_dom_children(), dom_walker::bb_reachable(), dom_walker::before_dom_children(), CDI_DOMINATORS, cfun, dump_file, dump_flags, EDGE_COUNT, ENTRY_BLOCK_PTR_FOR_FN, EXIT_BLOCK_PTR_FOR_FN, first_dom_son(), FOR_EACH_EDGE, free(), i, last_basic_block_for_fn, dom_walker::m_bb_to_rpo, dom_walker::m_dom_direction, dom_walker::m_reachability, dom_walker::m_unreachable_dom, dom_walker::m_user_bb_to_rpo, n_basic_blocks_for_fn, next_dom_son(), NULL, pre_and_rev_post_order_compute(), basic_block_def::preds, dom_walker::propagate_unreachable_to_edges(), dom_walker::REACHABLE_BLOCKS, set_all_edges_as_executable(), sort_bbs_postorder(), dom_walker::STOP, basic_block_def::succs, and worklist.
Referenced by array_bounds_checker::check(), eliminate_with_rpo_vn(), find_comparisons(), get_non_trapping(), ipa_analyze_node(), ipcp_transform_function(), rewrite_blocks(), and substitute_and_fold_engine::substitute_and_fold().
|
privateinherited |
Referenced by dom_walker::walk(), and dom_walker::~dom_walker().
bool strlen_pass::m_cleanup_cfg |
Referenced by before_dom_children().
|
privateinherited |
Referenced by dom_walker::walk().
gimple_stmt_iterator strlen_pass::m_gsi |
Referenced by before_dom_children(), check_and_optimize_call(), check_and_optimize_stmt(), handle_alloc_call(), handle_builtin_memcmp(), handle_builtin_memcpy(), handle_builtin_memset(), handle_builtin_strcat(), handle_builtin_strchr(), handle_builtin_strcpy(), handle_builtin_string_cmp(), handle_builtin_strlen(), handle_builtin_stxncpy_strncat(), handle_integral_assign(), handle_pointer_plus(), and handle_store().
|
privateinherited |
Referenced by dom_walker::bb_reachable(), and dom_walker::walk().
|
privateinherited |
Referenced by dom_walker::bb_reachable(), dom_walker::propagate_unreachable_to_edges(), and dom_walker::walk().
|
privateinherited |
Referenced by dom_walker::walk(), and dom_walker::~dom_walker().
pointer_query strlen_pass::ptr_qry |
Referenced by rewrite_update_dom_walker::before_dom_children(), and dom_walker::walk().