Commit 7ad491c6 by Martin Sebor Committed by Martin Sebor

PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member array

gcc/ChangeLog:

	PR tree-optimization/85753
	* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Handle
	RECORD_TYPE in addition to ARRAY_TYPE.

gcc/testsuite/ChangeLog:

	PR tree-optimization/85753
	* gcc.dg/Wrestrict-10.c: Adjust.
	* gcc.dg/Wrestrict-16.c: New test.

From-SVN: r260280
parent e4a14896
2018-05-15 Martin Sebor <msebor@redhat.com>
PR tree-optimization/85753
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Handle
RECORD_TYPE in addition to ARRAY_TYPE.
2018-05-15 Martin Sebor <msebor@redhat.com>
PR middle-end/85643
* calls.c (get_attr_nonstring_decl): Handle MEM_REF.
......
......@@ -263,27 +263,29 @@ builtin_memref::builtin_memref (tree expr, tree size)
else
sizrange[1] = maxobjsize;
if (!DECL_P (base))
return;
/* If the offset could be in the range of the referenced object
constrain its bounds so neither exceeds those of the object. */
if (offrange[0] < 0 && offrange[1] > 0)
offrange[0] = 0;
offset_int maxoff = maxobjsize;
tree basetype = TREE_TYPE (base);
if (DECL_P (base) && TREE_CODE (basetype) == ARRAY_TYPE)
if (TREE_CODE (basetype) == ARRAY_TYPE
&& ref
&& array_at_struct_end_p (ref))
; /* Use the maximum possible offset for last member arrays. */
else if (tree basesize = TYPE_SIZE_UNIT (basetype))
maxoff = wi::to_offset (basesize);
if (offrange[0] >= 0)
{
/* If the offset could be in range of the referenced object
constrain its bounds so neither exceeds those of the object. */
if (offrange[0] < 0 && offrange[1] > 0)
offrange[0] = 0;
offset_int maxoff = maxobjsize;
if (ref && array_at_struct_end_p (ref))
; /* Use the maximum possible offset for last member arrays. */
else if (tree basesize = TYPE_SIZE_UNIT (basetype))
maxoff = wi::to_offset (basesize);
if (offrange[0] >= 0)
{
if (offrange[1] < 0)
offrange[1] = offrange[0] <= maxoff ? maxoff : maxobjsize;
else if (offrange[0] <= maxoff && offrange[1] > maxoff)
offrange[1] = maxoff;
}
if (offrange[1] < 0)
offrange[1] = offrange[0] <= maxoff ? maxoff : maxobjsize;
else if (offrange[0] <= maxoff && offrange[1] > maxoff)
offrange[1] = maxoff;
}
}
......
2018-05-15 Martin Sebor <msebor@redhat.com>
PR tree-optimization/85753
* gcc.dg/Wrestrict-10.c: Adjust.
* gcc.dg/Wrestrict-16.c: New test.
2018-05-15 Martin Sebor <msebor@redhat.com>
PR middle-end/85643
* c-c++-common/attr-nonstring-7.c: New test.
......
......@@ -58,7 +58,7 @@ test_arr_strncat_2 (void)
void __attribute__ ((noclone, noinline))
test_arr_strcpy_1 (void)
{
strcpy (&b.a[i], b.a);
strcpy (&b.a[i], b.a); /* { dg-warning "\\\[-Wrestrict" } */
}
void __attribute__ ((noclone, noinline))
......
/* PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member
array
{ dg-do compile }
{ dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
#define memcpy __builtin_memcpy
char a[16];
struct { char a[16]; } x;
/* Exercise aggregate types. */
void test_aggr_idx_nowarn (int i, int j)
{
memcpy (&a[i], &a[j], 7);
memcpy (&x.a[i], &x.a[j], 7);
}
void test_aggr_idx_warn (int i, int j)
{
memcpy (&a[i], &a[j], 9); /* { dg-warning "\\\[-Wrestrict" } */
memcpy (&x.a[i], &x.a[j], 9); /* { dg-warning "\\\[-Wrestrict" } */
}
void test_aggr_off_nowarn (int i, int j)
{
memcpy (a + i, a + j, 5);
memcpy (x.a + i, x.a + j, 5);
}
void test_aggr_off_warn (int i, int j)
{
memcpy (a + i, a + j, 9); /* { dg-warning "\\\[-Wrestrict" } */
memcpy (x.a + i, x.a + j, 9); /* { dg-warning "\\\[-Wrestrict" } */
}
void sink (void*);
#define T(call) sink (call)
/* Also exercise basic types. */
#ifdef __UINT32_TYPE__
__UINT32_TYPE__ i32;
void test_basic_32 (int i, int j)
{
char *p = (char*)&i32;
T (memcpy (&p[i], &p[j], 1));
T (memcpy (&p[i], &p[j], 2));
T (memcpy (&p[i], &p[j], 3)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (p + i, p + j, 1));
T (memcpy (p + i, p + j, 2));
T (memcpy (p + i, p + j, 3)); /* { dg-warning "\\\[-Wrestrict" } */
}
#endif
#ifdef __UINT64_TYPE__
__UINT64_TYPE__ i64;
void test_basic_64 (int i, int j)
{
char *p = (char*)&i64;
T (memcpy (&p[i], &p[j], 1));
T (memcpy (&p[i], &p[j], 2));
T (memcpy (&p[i], &p[j], 3));
T (memcpy (&p[i], &p[j], 5)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (&p[i], &p[j], 6)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (&p[i], &p[j], 7)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (p + i, p + j, 1));
T (memcpy (p + i, p + j, 2));
T (memcpy (p + i, p + j, 3));
T (memcpy (p + i, p + j, 5)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (p + i, p + j, 6)); /* { dg-warning "\\\[-Wrestrict" } */
T (memcpy (p + i, p + j, 7)); /* { dg-warning "\\\[-Wrestrict" } */
}
#endif
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