aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2019-11-05 17:05:33 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2019-11-05 10:05:33 -0700
commit8299dfae9364468096a8005c4b3a83d4fa0f6e42 (patch)
tree91b38228622227e0e765dfeb1f81e4a365f3ae48 /gcc/tree-vrp.c
parent3fd4f9242d9b7d2032126dc4851b4fdf5628dc35 (diff)
downloadgcc-8299dfae9364468096a8005c4b3a83d4fa0f6e42.zip
gcc-8299dfae9364468096a8005c4b3a83d4fa0f6e42.tar.gz
gcc-8299dfae9364468096a8005c4b3a83d4fa0f6e42.tar.bz2
PR middle-end/92333 - missing variable name referencing VLA in warnings
PR middle-end/92333 - missing variable name referencing VLA in warnings PR middle-end/82608 - missing -Warray-bounds on an out-of-bounds VLA index gcc/testsuite/ChangeLog: PR middle-end/92333 PR middle-end/82608 * gcc.dg/Warray-bounds-51.c: New test. gcc/ChangeLog: PR middle-end/92333 PR middle-end/82608 * tree-vrp.c (vrp_prop::check_array_ref): Handle VLAs with constant size. * tree-ssa-ccp.c (fold_builtin_alloca_with_align): Use a meaninful name and location for a temporary variable. From-SVN: r277854
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 64fb76b..9889095 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4085,6 +4085,9 @@ vrp_prop::check_array_ref (location_t location, tree ref,
tree up_sub = low_sub;
tree up_bound = array_ref_up_bound (ref);
+ /* Referenced decl if one can be determined. */
+ tree decl = NULL_TREE;
+
/* Set for accesses to interior zero-length arrays. */
bool interior_zero_len = false;
@@ -4115,7 +4118,8 @@ vrp_prop::check_array_ref (location_t location, tree ref,
tree arg = TREE_OPERAND (ref, 0);
poly_int64 off;
- if (TREE_CODE (arg) == COMPONENT_REF)
+ const bool compref = TREE_CODE (arg) == COMPONENT_REF;
+ if (compref)
{
/* Try to determine the size of the trailing array from
its initializer (if it has one). */
@@ -4124,12 +4128,27 @@ vrp_prop::check_array_ref (location_t location, tree ref,
maxbound = refsize;
}
- if (maxbound == ptrdiff_max
- && get_addr_base_and_unit_offset (arg, &off)
- && known_gt (off, 0))
- maxbound = wide_int_to_tree (sizetype,
- wi::sub (wi::to_wide (maxbound),
- off));
+ if (maxbound == ptrdiff_max)
+ {
+ /* Try to determine the size of the base object. Avoid
+ COMPONENT_REF already tried above. Using its DECL_SIZE
+ size wouldn't necessarily be correct if the reference is
+ to its flexible array member initialized in a different
+ translation unit. */
+ tree base = get_addr_base_and_unit_offset (arg, &off);
+ if (!compref && base && DECL_P (base))
+ if (tree basesize = DECL_SIZE_UNIT (base))
+ if (TREE_CODE (basesize) == INTEGER_CST)
+ {
+ maxbound = basesize;
+ decl = base;
+ }
+
+ if (known_gt (off, 0))
+ maxbound = wide_int_to_tree (sizetype,
+ wi::sub (wi::to_wide (maxbound),
+ off));
+ }
else
maxbound = fold_convert (sizetype, maxbound);
@@ -4214,7 +4233,7 @@ vrp_prop::check_array_ref (location_t location, tree ref,
fprintf (dump_file, "\n");
}
- ref = TREE_OPERAND (ref, 0);
+ ref = decl ? decl : TREE_OPERAND (ref, 0);
tree rec = NULL_TREE;
if (TREE_CODE (ref) == COMPONENT_REF)