diff options
author | Martin Sebor <msebor@redhat.com> | 2019-07-25 00:29:17 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-07-24 18:29:17 -0600 |
commit | b631bdb3c16e85f35d38e39b3d315c35e4a5747c (patch) | |
tree | 946823534c8cde2d83143cbdcd1e5d6e8d8d7955 /gcc/testsuite/gcc.dg/Wstringop-overflow-14.c | |
parent | 7214f11d4708a62868f4b0830ef65b87976d1826 (diff) | |
download | gcc-b631bdb3c16e85f35d38e39b3d315c35e4a5747c.zip gcc-b631bdb3c16e85f35d38e39b3d315c35e4a5747c.tar.gz gcc-b631bdb3c16e85f35d38e39b3d315c35e4a5747c.tar.bz2 |
PR tree-optimization/91183 - strlen of a strcpy result with a conditional source not folded
PR tree-optimization/91183 - strlen of a strcpy result with a conditional source not folded
PR tree-optimization/86688 - missing -Wstringop-overflow using a non-string local array in strnlen with excessive bound
gcc/ChangeLog:
PR tree-optimization/91183
PR tree-optimization/86688
* builtins.c (compute_objsize): Handle MEM_REF.
* tree-ssa-strlen.c (class ssa_name_limit_t): New.
(get_min_string_length): Remove.
(count_nonzero_bytes): New function.
(handle_char_store): Rename...
(handle_store): to this. Handle multibyte stores via integer types.
(strlen_check_and_optimize_stmt): Adjust conditional and the called
function name.
gcc/testsuite/ChangeLog:
PR tree-optimization/91183
PR tree-optimization/86688
* gcc.dg/Wstringop-overflow-14.c: New test.
* gcc.dg/attr-nonstring-2.c: Remove xfails.
* gcc.dg/strlenopt-70.c: New test.
* gcc.dg/strlenopt-71.c: New test.
* gcc.dg/strlenopt-72.c: New test.
* gcc.dg/strlenopt-8.c: Remove xfails.
From-SVN: r273783
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wstringop-overflow-14.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Wstringop-overflow-14.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-14.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-14.c new file mode 100644 index 0000000..d23a248 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-14.c @@ -0,0 +1,49 @@ +/* Test to verify that past-the-end multibyte writes via lvalues of wider + types than char are diagnosed. + { dg-do compile } + { dg-require-effective-target int32plus } + { dg-options "-O2 -Wall" } */ + +typedef __INT16_TYPE__ int16_t; +typedef __INT32_TYPE__ int32_t; +typedef __INT64_TYPE__ int64_t; +typedef __SIZE_TYPE__ size_t; + +void* memcpy (void*, const void*, size_t); +char* strcpy (char*, const char*); + +char a4[4], a8[8], a16[16]; + +const char s4[] = "1234"; +const char t4[] = "4321"; + +void test_memcpy_cond (int i) +{ + char *p = a4 + 1; + const char *q = i ? s4 : t4; + memcpy (p, q, 4); // { dg-warning "writing 4 bytes into a region of size 3" } +} + + +void test_int16 (void) +{ + char *p = a4 + 1; + *(int16_t*)p = 0; + *(int16_t*)(p + 2) = 0; // { dg-warning "writing 2 bytes into a region of size 1" } +} + + +void test_int32 (void) +{ + char *p = a8 + 3; + *(int32_t*)p = 0; + *(int32_t*)(p + 2) = 0; // { dg-warning "writing 4 bytes into a region of size 3" } +} + + +void test_int64 (void) +{ + char *p = a16 + 5; + *(int64_t*)p = 0; + *(int64_t*)(p + 5) = 0; // { dg-warning "writing 8 bytes into a region of size 6" } +} |