aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-05-18 15:07:48 -0600
committerMartin Sebor <msebor@redhat.com>2020-05-18 15:07:48 -0600
commit3956244c58acceebf1ef2cf9a63e99f0f82abcb7 (patch)
tree8f8e1b8c745a4a28fe13858fa9714341af118a59 /gcc/tree-vrp.c
parent628bb8040858e0b3446e5f6740c0c0f557d3abdc (diff)
downloadgcc-3956244c58acceebf1ef2cf9a63e99f0f82abcb7.zip
gcc-3956244c58acceebf1ef2cf9a63e99f0f82abcb7.tar.gz
gcc-3956244c58acceebf1ef2cf9a63e99f0f82abcb7.tar.bz2
PR middle-end/94940 - spurious -Warray-bounds for a zero length array member of union
gcc/testsuite/ChangeLog: PR middle-end/94940 * gcc.dg/Warray-bounds-61.c: New test. gcc/ChangeLog: PR middle-end/94940 * tree-vrp.c (vrp_prop::check_mem_ref): Remove unreachable code. * tree.c (component_ref_size): Correct the handling or array members of unions. Drop a pointless test. Rename a local variable.
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r--gcc/tree-vrp.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 4b5df54..67c76db 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4009,15 +4009,11 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
else
arrbounds[1] = wi::lrshift (maxobjsize, wi::floor_log2 (eltsize));
- if (TREE_CODE (ref) == MEM_REF)
- {
- /* For MEM_REF determine a tighter bound of the non-array
- element type. */
- tree eltype = TREE_TYPE (reftype);
- while (TREE_CODE (eltype) == ARRAY_TYPE)
- eltype = TREE_TYPE (eltype);
- eltsize = wi::to_offset (TYPE_SIZE_UNIT (eltype));
- }
+ /* Determine a tighter bound of the non-array element type. */
+ tree eltype = TREE_TYPE (reftype);
+ while (TREE_CODE (eltype) == ARRAY_TYPE)
+ eltype = TREE_TYPE (eltype);
+ eltsize = wi::to_offset (TYPE_SIZE_UNIT (eltype));
}
else
{
@@ -4050,27 +4046,17 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
if (TREE_CODE (reftype) != ARRAY_TYPE)
reftype = build_array_type_nelts (reftype, 1);
- if (TREE_CODE (ref) == MEM_REF)
- {
- /* Extract the element type out of MEM_REF and use its size
- to compute the index to print in the diagnostic; arrays
- in MEM_REF don't mean anything. A type with no size like
- void is as good as having a size of 1. */
- tree type = TREE_TYPE (ref);
- while (TREE_CODE (type) == ARRAY_TYPE)
- type = TREE_TYPE (type);
- if (tree size = TYPE_SIZE_UNIT (type))
- {
- offrange[0] = offrange[0] / wi::to_offset (size);
- offrange[1] = offrange[1] / wi::to_offset (size);
- }
- }
- else
+ /* Extract the element type out of MEM_REF and use its size
+ to compute the index to print in the diagnostic; arrays
+ in MEM_REF don't mean anything. A type with no size like
+ void is as good as having a size of 1. */
+ tree type = TREE_TYPE (ref);
+ while (TREE_CODE (type) == ARRAY_TYPE)
+ type = TREE_TYPE (type);
+ if (tree size = TYPE_SIZE_UNIT (type))
{
- /* For anything other than MEM_REF, compute the index to
- print in the diagnostic as the offset over element size. */
- offrange[0] = offrange[0] / eltsize;
- offrange[1] = offrange[1] / eltsize;
+ offrange[0] = offrange[0] / wi::to_offset (size);
+ offrange[1] = offrange[1] / wi::to_offset (size);
}
bool warned;