Commit a411ae9b by Martin Sebor Committed by Martin Sebor

PR tree-optimization/89350 - Wrong -Wstringop-overflow= warning since r261518

gcc/ChangeLog:

	PR tree-optimization/89350
	* builtins.c (compute_objsize): Also ignore offsets whose upper
	bound is negative.
	* gimple-ssa-warn-restrict.c (builtin_memref): Add new member.
	(builtin_memref::builtin_memref): Initialize new member.
	Allow EXPR to be null.
	(builtin_memref::extend_offset_range): Replace local with a member.
	Avoid assuming pointer offsets are unsigned.
	(builtin_memref::set_base_and_offset): Determine base object
	before computing offset range.
	(builtin_access::builtin_access): Handle memset.
	(builtin_access::generic_overlap): Replace local with a member.
	(builtin_access::strcat_overlap): Same.
	(builtin_access::overlap): Same.
	(maybe_diag_overlap): Same.
	(maybe_diag_access_bounds): Same.
	(wrestrict_dom_walker::check_call): Handle memset.
	(check_bounds_or_overlap): Same.

gcc/testsuite/ChangeLog:

	PR tree-optimization/89350
	* gcc.dg/Wstringop-overflow.c: Xfail overly ambitious tests.
	* gcc.dg/Wstringop-overflow-11.c: New test.
	* gcc.dg/Wstringop-overflow-12.c: New test.
	* gcc.dg/pr89350.c: New test.
	* gcc.dg/pr40340-1.c: Adjust expected warning.
	* gcc.dg/pr40340-2.c: Same.
	* gcc.dg/pr40340-4.c: Same.
	* gcc.dg/pr40340-5.c: Same.

From-SVN: r269867
parent 11bf9a07
2019-03-21 Martin Sebor <msebor@redhat.com>
PR tree-optimization/89350
* builtins.c (compute_objsize): Also ignore offsets whose upper
bound is negative.
* gimple-ssa-warn-restrict.c (builtin_memref): Add new member.
(builtin_memref::builtin_memref): Initialize new member.
Allow EXPR to be null.
(builtin_memref::extend_offset_range): Replace local with a member.
Avoid assuming pointer offsets are unsigned.
(builtin_memref::set_base_and_offset): Determine base object
before computing offset range.
(builtin_access::builtin_access): Handle memset.
(builtin_access::generic_overlap): Replace local with a member.
(builtin_access::strcat_overlap): Same.
(builtin_access::overlap): Same.
(maybe_diag_overlap): Same.
(maybe_diag_access_bounds): Same.
(wrestrict_dom_walker::check_call): Handle memset.
(check_bounds_or_overlap): Same.
2019-03-21 Jan Hubicka <hubicka@ucw.cz> 2019-03-21 Jan Hubicka <hubicka@ucw.cz>
Jakub Jelinek <jakub@redhat.com> Jakub Jelinek <jakub@redhat.com>
......
...@@ -3650,7 +3650,8 @@ compute_objsize (tree dest, int ostype) ...@@ -3650,7 +3650,8 @@ compute_objsize (tree dest, int ostype)
/* Ignore negative offsets for now. For others, /* Ignore negative offsets for now. For others,
use the lower bound as the most optimistic use the lower bound as the most optimistic
estimate of the (remaining)size. */ estimate of the (remaining)size. */
if (wi::sign_mask (min)) if (wi::sign_mask (min)
|| wi::sign_mask (max))
; ;
else if (wi::ltu_p (min, wisiz)) else if (wi::ltu_p (min, wisiz))
return wide_int_to_tree (TREE_TYPE (size), return wide_int_to_tree (TREE_TYPE (size),
......
2019-03-21 Martin Sebor <msebor@redhat.com>
PR tree-optimization/89350
* gcc.dg/Warray-bounds-40.c: Remove an xfail.
* gcc.dg/Wstringop-overflow.c: Xfail overly ambitious tests.
* gcc.dg/Wstringop-overflow-11.c: New test.
* gcc.dg/Wstringop-overflow-12.c: New test.
* gcc.dg/pr89350.c: New test.
* gcc.dg/pr40340-1.c: Adjust expected warning.
* gcc.dg/pr40340-2.c: Same.
* gcc.dg/pr40340-4.c: Same.
* gcc.dg/pr40340-5.c: Same.
2019-03-21 Jakub Jelinek <jakub@redhat.com> 2019-03-21 Jakub Jelinek <jakub@redhat.com>
PR lto/89692 PR lto/89692
......
...@@ -42,7 +42,7 @@ void test_memmove (void) ...@@ -42,7 +42,7 @@ void test_memmove (void)
void test_memset (void) void test_memset (void)
{ {
memset (d, 0, SIZE_MAX - 2); /* { dg-warning ".memset. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" "bug" { xfail *-*-* } } */ memset (d, 0, SIZE_MAX - 2); /* { dg-warning ".memset. pointer overflow between offset 0 and size \[0-9\]+ \\\[-Warray-bounds" } */
} }
......
/* PR tree-optimization/89350 - Wrong -Wstringop-overflow warning
on a variable offset from the end of an array
Test exercising -Wstringop-truncation alone, with -Warray-bounds
explicitly disabled.
{ dg-do compile }
{ dg-options "-O2 -Wno-array-bounds -Wstringop-overflow -ftrack-macro-expansion=0" } */
#include "range.h"
extern void* memcpy (void*, const void*, size_t);
extern void* memset (void*, int, size_t);
void sink (void*);
extern char ga7[7];
#define T(d, n) (memcpy ((d), s, (n)), sink (d))
void test_memcpy_array_cst_range_off (const void *s)
{
char *d = ga7 + 1;
T (d + UR (1, 2), 1);
T (d + UR (1, 2), 5);
T (d + UR (0, 1), 6);
T (d + UR (0, 1), 7); /* { dg-warning ".memcpy. writing 6 bytes into a region of size 5 overflows the destination" "pr89428" { xfail *-*-* } } */
T (d + UR (1, 2), 6); /* { dg-warning ".memcpy. writing 6 bytes into a region of size 5 overflows the destination" } */
T (d + UR (1, 2), 7); /* { dg-warning "writing 7 bytes into a region of size 5 " } */
T (d + SR (-3, -2), 1); /* { dg-warning "writing 1 byte into a region of size 0 " "pr85350" { xfail *-*-* } } */
T (d + SR (-2, -1), 1);
T (d + SR (-2, -1), 2); /* { dg-warning "writing 2 bytes into a region of size 7 " "pr89428" { xfail *-*-* } } */
T (d + SR (-2, -1), 9); /* { dg-warning "writing 9 bytes into a region of size 7 " "pr85350" { xfail *-*-* } } */
d = ga7 + 7;
T (d + SR (-7, -6), 1);
T (d + SR (-7, -1), 1);
T (d + SR (-2, -1), 3); /* { dg-warning "writing 3 bytes into a region of size 2 " "pr85350" { xfail *-*-* } } */
T (d + UR (1, 2), 1); /* { dg-warning "writing 1 byte into a region of size 0 " "pr89350" { xfail *-*-* } } */
}
void test_memcpy_array_range_range_off (const void *s)
{
char *d = ga7 + UR (0, 1);
T (d + SR (-1, 0), 1);
T (d + SR (-1, 0), 7);
T (d + SR (-1, 0), 9); /* { dg-warning "writing 1 byte into a region of size 0 " "pr89350" { xfail *-*-* } } */
}
#undef T
#define T(d, n) (memset ((d), 0, (n)), sink (d))
void test_memset_array_unsigned_off (void)
{
char *d = ga7 + 1;
T (d + UR (1, 2), 1);
T (d + UR (1, 2), 5);
T (d + UR (0, 1), 6);
T (d + UR (0, 1), 7); /* { dg-warning ".memset. writing 6 bytes into a region of size 5 overflows the destination" "pr89428" { xfail *-*-* } } */
T (d + UR (1, 2), 6); /* { dg-warning ".memset. writing 6 bytes into a region of size 5 overflows the destination" } */
T (d + UR (1, 2), 7); /* { dg-warning "writing 7 bytes into a region of size 5 " } */
T (d + SR (-3, -2), 1); /* { dg-warning "writing 1 byte into a region of size 0 " "pr85350" { xfail *-*-* } } */
T (d + SR (-2, -1), 1);
T (d + SR (-2, -1), 2); /* { dg-warning "writing 2 bytes into a region of size 7 " "pr89428" { xfail *-*-* } } */
T (d + SR (-2, -1), 9); /* { dg-warning "writing 9 bytes into a region of size 7 " "pr85350" { xfail *-*-* } } */
d = ga7 + 7;
T (d + SR (-7, -6), 1);
T (d + SR (-7, -1), 1);
T (d + SR (-2, -1), 3); /* { dg-warning "writing 3 bytes into a region of size 2 " "pr85350" { xfail *-*-* } } */
T (d + UR (1, 2), 1); /* { dg-warning "writing 1 byte into a region of size 0 " } */
}
struct MemArray { char a7[7], a3[3], c; };
extern struct MemArray gma;
void test_memset_memarray (void)
{
char *d = gma.a7 + 1;
T (d + UR (1, 2), 1);
T (d + UR (1, 2), 5);
T (d + UR (0, 1), 6);
T (d + UR (0, 1), 7); /* { dg-warning ".memset. writing 6 bytes into a region of size 5 overflows the destination" "pr89428" { xfail *-*-* } } */
T (d + UR (1, 2), 6); /* { dg-warning ".memset. writing 6 bytes into a region of size 5 overflows the destination" "pr89350" { xfail *-*-* } } */
T (d + UR (1, 2), 7); /* { dg-warning "writing 7 bytes into a region of size 5 " "pr85350" { xfail *-*-* } } */
}
#undef T
#define T(d, n) (memcpy ((d), s, (n)), sink (d))
void test_memcpy_array_signed_off (const void *s)
{
char *d = ga7 + 1;
T (d + SR (-7, 7), 7);
T (d + SR (-1, 1), 7);
T (d + SR (-1, 1), 9); /* { dg-warning "writing 9 bytes into a region of size " "pr89428" { xfail *-*-* } } */
T (d + SR (-1, 2), 9); /* { dg-warning "writing 9 bytes into a region of size " "pr89428" { xfail *-*-* } } */
T (d + SR (1, 2), 1);
T (d + SR (1, 2), 5);
T (d + SR (0, 1), 6);
T (d + UR (1, 2), 7); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
}
...@@ -51,8 +51,8 @@ void test_memcpy_array (const void *s) ...@@ -51,8 +51,8 @@ void test_memcpy_array (const void *s)
T (a7 + UR (8, 9), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (8, 9), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */
T (a7 + UR (9, 10), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (9, 10), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */
T (a7 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" "pr85350" { xfail *-*-* } } */
T (a7 + UR (DIFF_MAX, SIZE_MAX), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (DIFF_MAX, SIZE_MAX), s, 7); /* { dg-warning "writing 7 bytes into a region of size 0" "pr85350" { xfail *-*-*} } */
/* This is valid. */ /* This is valid. */
char *d = a7 + 7; char *d = a7 + 7;
...@@ -102,8 +102,8 @@ void test_strcpy_array (void) ...@@ -102,8 +102,8 @@ void test_strcpy_array (void)
T (a7 + UR (8, 9), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (8, 9), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */
T (a7 + UR (9, 10), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (9, 10), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */
T (a7 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" "pr85350" { xfail *-*-* } } */
T (a7 + UR (DIFF_MAX, SIZE_MAX), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" } */ T (a7 + UR (DIFF_MAX, SIZE_MAX), "012345"); /* { dg-warning "writing 7 bytes into a region of size 0" "pr85350" { xfail *-*-* } } */
char *d = a7 + 7; char *d = a7 + 7;
...@@ -127,6 +127,6 @@ void test_strncpy_memarray (struct MemArray *p, const void *s) ...@@ -127,6 +127,6 @@ void test_strncpy_memarray (struct MemArray *p, const void *s)
T (p->a9 + UR (9, 10), s, 9); /* { dg-warning "writing 9 bytes into a region of size 0" } */ T (p->a9 + UR (9, 10), s, 9); /* { dg-warning "writing 9 bytes into a region of size 0" } */
T (p->a9 + UR (10, 11), s, 9); /* { dg-warning "writing 9 bytes into a region of size 0" } */ T (p->a9 + UR (10, 11), s, 9); /* { dg-warning "writing 9 bytes into a region of size 0" } */
T (p->a9 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), s, 1); /* { dg-warning "writing 1 byte into a region of size 0" } */ T (p->a9 + UR (DIFF_MAX, DIFF_MAX + (size_t)1), s, 1); /* { dg-warning "writing 1 byte into a region of size 0" "pr85350" { xfail *-*-* } } */
T (p->a9 + UR (DIFF_MAX, SIZE_MAX), s, 3); /* { dg-warning "writing 3 bytes into a region of size 0" } */ T (p->a9 + UR (DIFF_MAX, SIZE_MAX), s, 3); /* { dg-warning "writing 3 bytes into a region of size 0" "pr85350" { xfail *-*-* } } */
} }
...@@ -20,5 +20,5 @@ main (void) ...@@ -20,5 +20,5 @@ main (void)
return 0; return 0;
} }
/* { dg-warning "writing" "" { target *-*-* } 10 } */ /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "" { target *-*-* } 10 } */
/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ /* { dg-message "file included" "In file included" { target *-*-* } 0 } */
...@@ -12,5 +12,5 @@ main (void) ...@@ -12,5 +12,5 @@ main (void)
return 0; return 0;
} }
/* { dg-warning "writing" "" { target *-*-* } 10 } */ /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "" { target *-*-* } 10 } */
/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ /* { dg-message "file included" "In file included" { target *-*-* } 0 } */
/* PR middle-end/40340 */ /* PR middle-end/40340 */
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -Wall -Wno-system-headers -g" } */ /* { dg-options "-O2 -Wall -Wno-array-bounds -Wno-system-headers -g" } */
#define TEST3 #define TEST3
#include "pr40340.h" #include "pr40340.h"
......
...@@ -13,5 +13,5 @@ main (void) ...@@ -13,5 +13,5 @@ main (void)
return 0; return 0;
} }
/* { dg-warning "writing" "" { target *-*-* } 10 } */ /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "" { target *-*-* } 10 } */
/* { dg-message "file included" "In file included" { target *-*-* } 0 } */ /* { dg-message "file included" "In file included" { target *-*-* } 0 } */
/* PR tree-optimization/89350 - Wrong -Wstringop-overflow warning
on a variable offset from the end of an array
{ dg-do compile }
{ dg-options "-O2 -Wall" } */
char buf[128];
char *src = "HCSparta";
int main(int argc, char **argv)
{
char *dst = buf + sizeof(buf);
if (argc)
{
dst -= argc;
__builtin_memcpy(dst, src, argc + 0); /* { dg-bogus "\\\[-Warray-bounds|-Wstringop-overflow" } */
}
}
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