Commit 129ef157 by Martin Sebor Committed by Martin Sebor

PR tree-optimization/89662 - -Warray-bounds ICE on void* arithmetic

gcc/ChangeLog:

	PR tree-optimization/89662
	* tree-vrp.c (vrp_prop::check_mem_ref): Avoid assuming every type
	has a size.

gcc/testsuite/ChangeLog:

	PR tree-optimization/89662
	* gcc.dg/Warray-bounds-41.c: New test.

From-SVN: r269655
parent bd8ea483
2019-03-13 Martin Sebor <msebor@redhat.com>
PR tree-optimization/89662
* tree-vrp.c (vrp_prop::check_mem_ref): Avoid assuming every type
has a size.
2019-03-13 Richard Biener <rguenther@suse.de> 2019-03-13 Richard Biener <rguenther@suse.de>
PR middle-end/89677 PR middle-end/89677
......
2019-03-13 Martin Sebor <msebor@redhat.com>
PR tree-optimization/89662
* gcc.dg/Warray-bounds-41.c: New test.
2019-03-13 Paolo Carlini <paolo.carlini@oracle.com> 2019-03-13 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63508 PR c++/63508
......
/* PR tree-optimization/89662- -Warray-bounds ICE on void* arithmetic
{ dg-do compile }
{ dg-options "-O2 -Wall" } */
void* vptr (void *c)
{
return c;
}
void sink (void*);
void test_vptr_arith_vla_cst (void)
{
int n = 1;
char c[n];
sink (vptr (c) - 1); /* { dg-warning "\\\[-Warray-bounds" } */
}
void test_vptr_arith_vla_range (int n)
{
if (n < 1 || 4 < n)
return;
char c[n];
sink (vptr (c) - 1); /* { dg-warning "\\\[-Warray-bounds" "pr82608" { xfail *-*-* } } */
}
void test_vptr_arith_vla_var (int n)
{
char c[n];
sink (vptr (c) - 1); /* { dg-warning "\\\[-Warray-bounds" "pr82608" { xfail *-*-* } } */
}
...@@ -4718,13 +4718,16 @@ vrp_prop::check_mem_ref (location_t location, tree ref, ...@@ -4718,13 +4718,16 @@ vrp_prop::check_mem_ref (location_t location, tree ref,
{ {
/* Extract the element type out of MEM_REF and use its size /* Extract the element type out of MEM_REF and use its size
to compute the index to print in the diagnostic; arrays to compute the index to print in the diagnostic; arrays
in MEM_REF don't mean anything. */ 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); tree type = TREE_TYPE (ref);
while (TREE_CODE (type) == ARRAY_TYPE) while (TREE_CODE (type) == ARRAY_TYPE)
type = TREE_TYPE (type); type = TREE_TYPE (type);
tree size = TYPE_SIZE_UNIT (type); if (tree size = TYPE_SIZE_UNIT (type))
offrange[0] = offrange[0] / wi::to_offset (size); {
offrange[1] = offrange[1] / wi::to_offset (size); offrange[0] = offrange[0] / wi::to_offset (size);
offrange[1] = offrange[1] / wi::to_offset (size);
}
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment