Array bounds checking.
Copyright (C) 2020-2024 Free Software Foundation, Inc.
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/>.
void array_bounds_checker::check_addr_expr |
( |
location_t | location, |
|
|
tree | t, |
|
|
gimple * | stmt ) |
|
private |
Searches if the expr T, located at LOCATION computes
address of an ARRAY_REF, and call check_array_ref on it.
References check_array_ref(), check_mem_ref(), DECL_P, DECL_SOURCE_LOCATION, dump_file, dump_flags, dump_generic_expr(), handled_component_p(), inform(), mem_ref_offset(), MSG_NOTE, wi::sdiv_trunc(), suppress_warning(), TDF_DETAILS, TDF_SLIM, wi::to_offset(), TREE_CODE, TREE_OPERAND, TREE_TYPE, TYPE_DOMAIN, TYPE_MAX_VALUE, TYPE_MIN_VALUE, TYPE_SIZE_UNIT, warning_at(), and warning_suppressed_p().
Referenced by check_array_bounds().
bool array_bounds_checker::check_array_ref |
( |
location_t | location, |
|
|
tree | ref, |
|
|
gimple * | stmt, |
|
|
bool | ignore_off_by_one ) |
|
private |
Checks one ARRAY_REF in REF, located at LOCUS. Ignores flexible
arrays and "struct" hacks. If VRP can determine that the array
subscript is a constant, check if it is outside valid range. If
the array subscript is a RANGE, warn if it is non-overlapping with
valid range. IGNORE_OFF_BY_ONE is true if the ARRAY_REF is inside
a ADDR_EXPR. Return true if a warning has been issued or if
no-warning is set.
References array_ref_up_bound(), check_out_of_bounds_and_warn(), component_ref_sam_type(), DECL_NOT_FLEXARRAY, DECL_P, DECL_SOURCE_LOCATION, dump_file, dump_flags, dump_generic_expr(), G_, get_legacy_range(), get_up_bounds_for_array_ref(), get_value_range(), inform(), int_0, MSG_NOTE, NULL_TREE, suppress_warning(), TDF_DETAILS, TDF_SLIM, trail_0, trail_1, trail_n, TREE_CODE, TREE_OPERAND, TREE_TYPE, vrange::undefined_p(), VAR_P, vrange::varying_p(), VR_RANGE, warning_at(), and warning_suppressed_p().
Referenced by check_addr_expr(), and check_array_bounds().
bool array_bounds_checker::check_mem_ref |
( |
location_t | location, |
|
|
tree | ref, |
|
|
bool | ignore_off_by_one ) |
|
private |
Checks one MEM_REF in REF, located at LOCATION, for out-of-bounds
references to string constants. If VRP can determine that the array
subscript is a constant, check if it is outside valid range.
If the array subscript is a RANGE, warn if it is non-overlapping
with valid range.
IGNORE_OFF_BY_ONE is true if the MEM_REF is inside an ADDR_EXPR
(used to allow one-past-the-end indices for code that takes
the address of the just-past-the-end element of an array).
Returns true if a warning has been issued.
References access_none, build_array_type_nelts(), build_printable_array_type(), pointer_query::get_ref(), i, access_ref::inform_access(), is_gimple_call(), m_ptr_qry, m_stmt, NULL, access_ref::offmax, access_ref::offrng, access_ref::offset_in_range(), POINTER_TYPE_P, access_ref::ref, access_ref::sizrng, SSA_NAME_DEF_STMT, strip_array_types(), suppress_warning(), wi::to_offset(), TREE_CODE, TREE_TYPE, TYPE_SIZE_UNIT, unsigned_char_type_node, warning_at(), and warning_suppressed_p().
Referenced by check_addr_expr(), and check_array_bounds().