diff options
author | Martin Sebor <msebor@redhat.com> | 2019-01-17 16:33:55 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-01-17 09:33:55 -0700 |
commit | 213694e56e6265044bc85dbf43bda9028f05dba7 (patch) | |
tree | 6e55de74c41ab1ba9949e3447f390dbb4c09b935 /gcc/testsuite/gcc.dg/builtin-memcpy.c | |
parent | 16d46c7bfda76b5b3e88a2d9a809aacdc3ed8e1a (diff) | |
download | gcc-213694e56e6265044bc85dbf43bda9028f05dba7.zip gcc-213694e56e6265044bc85dbf43bda9028f05dba7.tar.gz gcc-213694e56e6265044bc85dbf43bda9028f05dba7.tar.bz2 |
PR tree-optimization/88800 - Spurious -Werror=array-bounds for non-taken branch
gcc/ChangeLog:
PR tree-optimization/88800
* gimple-fold.c (gimple_fold_builtin_memory_op): Avoid checking
NO_WARNING bit here. Avoid folding out-of-bounds calls.
* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Remove
redundant argument. Add new argument and issue diagnostics under
its control. Detect out-of-bounds access even with warnings
disabled.
(check_bounds_or_overlap): Change return type. Add argument.
(wrestrict_dom_walker::check_call): Adjust.
* gimple-ssa-warn-restrict.h (check_bounds_or_overlap): Add argument.
* tree-ssa-strlen.c (handle_builtin_strcpy): Adjust to change in
check_bounds_or_overlap's return value.
(handle_builtin_stxncpy): Same.
(handle_builtin_strcat): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/88800
* c-c++-common/Wrestrict.c: Adjust.
* gcc.dg/Warray-bounds-37.c: New test.
* gcc.dg/builtin-memcpy-2.c: New test.
* gcc.dg/builtin-memcpy.c: New test.
From-SVN: r268037
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtin-memcpy.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/builtin-memcpy.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtin-memcpy.c b/gcc/testsuite/gcc.dg/builtin-memcpy.c new file mode 100644 index 0000000..85e2539 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-memcpy.c @@ -0,0 +1,43 @@ +/* PR tree-optimization/88800 - Spurious -Werror=array-bounds for non-taken + branch + Verify that out-of-bounds memcpy calls are not folded when warnings are + enabled (builtin-memcpy-2.c verifies they're not folded with warnings + disabled). + { dg-do compile } + { dg-options "-O2 -Wall -fdump-tree-optimized" } */ + +extern void* memcpy (void*, const void*, __SIZE_TYPE__); + +char a1[1], a2[2], a4[4], a8[8], a16[16], a32[32]; + +void f1 (const void *p) +{ + memcpy (a1, p, sizeof a1 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +void f2 (const void *p) +{ + memcpy (a2, p, sizeof a2 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +void f4 (const void *p) +{ + memcpy (a4, p, sizeof a4 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +void f8 (const void *p) +{ + memcpy (a8, p, sizeof a8 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +void f16 (const void *p) +{ + memcpy (a16, p, sizeof a16 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +void f32 (const void *p) +{ + memcpy (a32, p, sizeof a32 * 2); /* { dg-warning "\\\[-Warray-bounds" } */ +} + +/* { dg-final { scan-tree-dump-times "memcpy" 6 "optimized" } } */ |