GCC Middle and Back End API Reference
array_bounds_checker Class Reference

#include <gimple-array-bounds.h>

Collaboration diagram for array_bounds_checker:

Public Member Functions

 array_bounds_checker (struct function *, range_query *)
 
void check ()
 

Private Member Functions

bool check_array_ref (location_t, tree, gimple *, bool ignore_off_by_one)
 
bool check_mem_ref (location_t, tree, bool ignore_off_by_one)
 
void check_addr_expr (location_t, tree, gimple *)
 
void get_value_range (irange &r, const_tree op, gimple *)
 

Static Private Member Functions

static tree check_array_bounds (tree *tp, int *walk_subtree, void *data)
 

Private Attributes

struct functionfun
 
pointer_query m_ptr_qry
 
gimplem_stmt
 

Friends

class check_array_bounds_dom_walker
 

Detailed Description

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/>.   

Constructor & Destructor Documentation

◆ array_bounds_checker()

array_bounds_checker::array_bounds_checker ( struct function * func,
range_query * qry )
Array bounds checking.
   Copyright (C) 2005-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/>.   

Member Function Documentation

◆ check()

void array_bounds_checker::check ( )

◆ check_addr_expr()

void array_bounds_checker::check_addr_expr ( location_t location,
tree t,
gimple * stmt )
private

◆ check_array_bounds()

tree array_bounds_checker::check_array_bounds ( tree * tp,
int * walk_subtree,
void * data )
staticprivate
Callback for walk_tree to check a tree for out of bounds array
accesses.  The array_bounds_checker class is passed in DATA.   

References check_addr_expr(), check_array_ref(), check_mem_ref(), EXPR_HAS_LOCATION, EXPR_LOCATION, gcc_assert, ggc_alloc(), gimple_location(), inbounds_memaccess_p(), m_stmt, NULL_TREE, suppress_warning(), and TREE_CODE.

Referenced by check_array_bounds_dom_walker::before_dom_children().

◆ check_array_ref()

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(), ggc_alloc(), 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().

◆ check_mem_ref()

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(), ggc_alloc(), i, is_gimple_call(), m_ptr_qry, m_stmt, NULL, POINTER_TYPE_P, 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().

◆ get_value_range()

void array_bounds_checker::get_value_range ( irange & r,
const_tree op,
gimple * stmt )
private

Friends And Related Symbol Documentation

◆ check_array_bounds_dom_walker

Field Documentation

◆ fun

struct function* array_bounds_checker::fun
private

Referenced by check().

◆ m_ptr_qry

pointer_query array_bounds_checker::m_ptr_qry
private

Referenced by check_mem_ref(), and get_value_range().

◆ m_stmt

gimple* array_bounds_checker::m_stmt
private

The documentation for this class was generated from the following files: