aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-07-26 09:47:42 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-07-26 11:55:24 +0200
commitdd44445f09bcf92198e9238a28bf026959152be1 (patch)
tree5758cdc6fec2bd1a34a0996e6482395461b6fb31 /gcc
parent1ab2270036dc0f2a13442ce682267bc7433ffb34 (diff)
downloadgcc-dd44445f09bcf92198e9238a28bf026959152be1.zip
gcc-dd44445f09bcf92198e9238a28bf026959152be1.tar.gz
gcc-dd44445f09bcf92198e9238a28bf026959152be1.tar.bz2
Pass gimple context to array_bounds_checker.
I have changed the use of the array_bounds_checker in VRP to use a ranger in my local tree to make sure there are no regressions when using either VRP or the ranger. In doing so I noticed that the checker does not pass context to get_value_range, which causes the ranger to miss a few cases. This patch fixes the oversight. Tested on x86-64 Linux using the array bounds checker both with VRP and the ranger. gcc/ChangeLog: * gimple-array-bounds.cc (array_bounds_checker::get_value_range): Add gimple argument. (array_bounds_checker::check_array_ref): Same. (array_bounds_checker::check_addr_expr): Same. (array_bounds_checker::check_array_bounds): Pass statement to check_array_bounds and check_addr_expr. * gimple-array-bounds.h (check_array_bounds): Add gimple argument. (check_addr_expr): Same. (get_value_range): Same.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-array-bounds.cc17
-rw-r--r--gcc/gimple-array-bounds.h6
2 files changed, 12 insertions, 11 deletions
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 8dfd6f9..598c76b 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -43,9 +43,9 @@ along with GCC; see the file COPYING3. If not see
// break the dependency on equivalences for this pass.
const value_range *
-array_bounds_checker::get_value_range (const_tree op)
+array_bounds_checker::get_value_range (const_tree op, gimple *stmt)
{
- return ranges->get_value_range (op);
+ return ranges->get_value_range (op, stmt);
}
/* Try to determine the DECL that REF refers to. Return the DECL or
@@ -173,7 +173,7 @@ trailing_array (tree arg, tree *pref)
bool
array_bounds_checker::check_array_ref (location_t location, tree ref,
- bool ignore_off_by_one)
+ gimple *stmt, bool ignore_off_by_one)
{
if (warning_suppressed_p (ref, OPT_Warray_bounds))
/* Return true to have the caller prevent warnings for enclosing
@@ -287,7 +287,7 @@ array_bounds_checker::check_array_ref (location_t location, tree ref,
const value_range *vr = NULL;
if (TREE_CODE (low_sub) == SSA_NAME)
{
- vr = get_value_range (low_sub);
+ vr = get_value_range (low_sub, stmt);
if (!vr->undefined_p () && !vr->varying_p ())
{
low_sub = vr->kind () == VR_RANGE ? vr->max () : vr->min ();
@@ -563,7 +563,8 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
address of an ARRAY_REF, and call check_array_ref on it. */
void
-array_bounds_checker::check_addr_expr (location_t location, tree t)
+array_bounds_checker::check_addr_expr (location_t location, tree t,
+ gimple *stmt)
{
/* For the most significant subscript only, accept taking the address
of the just-past-the-end element. */
@@ -575,7 +576,7 @@ array_bounds_checker::check_addr_expr (location_t location, tree t)
bool warned = false;
if (TREE_CODE (t) == ARRAY_REF)
{
- warned = check_array_ref (location, t, ignore_off_by_one);
+ warned = check_array_ref (location, t, stmt, ignore_off_by_one);
ignore_off_by_one = false;
}
else if (TREE_CODE (t) == MEM_REF)
@@ -728,14 +729,14 @@ array_bounds_checker::check_array_bounds (tree *tp, int *walk_subtree,
bool warned = false;
array_bounds_checker *checker = (array_bounds_checker *) wi->info;
if (TREE_CODE (t) == ARRAY_REF)
- warned = checker->check_array_ref (location, t,
+ warned = checker->check_array_ref (location, t, wi->stmt,
false/*ignore_off_by_one*/);
else if (TREE_CODE (t) == MEM_REF)
warned = checker->check_mem_ref (location, t,
false /*ignore_off_by_one*/);
else if (TREE_CODE (t) == ADDR_EXPR)
{
- checker->check_addr_expr (location, t);
+ checker->check_addr_expr (location, t, wi->stmt);
*walk_subtree = false;
}
else if (inbounds_memaccess_p (t))
diff --git a/gcc/gimple-array-bounds.h b/gcc/gimple-array-bounds.h
index fa64262..d8f7ff7 100644
--- a/gcc/gimple-array-bounds.h
+++ b/gcc/gimple-array-bounds.h
@@ -31,10 +31,10 @@ public:
private:
static tree check_array_bounds (tree *tp, int *walk_subtree, void *data);
- bool check_array_ref (location_t, tree, bool ignore_off_by_one);
+ 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);
- const value_range *get_value_range (const_tree op);
+ void check_addr_expr (location_t, tree, gimple *);
+ const value_range *get_value_range (const_tree op, gimple *);
struct function *fun;
range_query *ranges;