diff options
author | Jeff Law <law@gcc.gnu.org> | 2018-12-05 16:10:08 -0700 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-12-05 16:10:08 -0700 |
commit | 665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4 (patch) | |
tree | 2c210ca46a2a9c1f9f7c1d5eb1b25887d17f511f /gcc/testsuite | |
parent | c43137e800bb9ca2ecda0a6b6189e0eb5c22f0d7 (diff) | |
download | gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.zip gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.tar.gz gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.tar.bz2 |
re PR c/87028 (false positive -Wstringop-truncation strncpy with global variable source string)
PR c/87028
* calls.c (get_attr_nonstring_decl): Avoid setting *REF to
SSA_NAME_VAR.
* gcc/gimple-low.c (lower_stmt): Fold builtin calls here.
* gimplify (maybe_fold_stmt): Avoid folding builtin calls.
PR c/87028
* c-c++-common/Wstringop-truncation.c: Remove xfails.
* gcc.dg/Wstringop-truncation-5.c: New test.
* gcc.dg/strcmpopt_1.c: Adjust.
* gcc.dg/tree-ssa/pr79697.c: Same.
From-SVN: r266833
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Wstringop-truncation.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wstringop-truncation-5.c | 128 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-bcopy.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/strcmpopt_1.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr79697.c | 4 |
6 files changed, 147 insertions, 12 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 77dbe74..8bed4b4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-12-05 Martin Sebor <msebor@redhat.com> + + PR c/87028 + * c-c++-common/Wstringop-truncation.c: Remove xfails. + * gcc.dg/Wstringop-truncation-5.c: New test. + * gcc.dg/strcmpopt_1.c: Adjust. + * gcc.dg/tree-ssa/pr79697.c: Same. + 2018-12-05 Richard Sandiford <richard.sandiford@arm.com> PR tree-optimization/88064 diff --git a/gcc/testsuite/c-c++-common/Wstringop-truncation.c b/gcc/testsuite/c-c++-common/Wstringop-truncation.c index e78e85e..b85711d 100644 --- a/gcc/testsuite/c-c++-common/Wstringop-truncation.c +++ b/gcc/testsuite/c-c++-common/Wstringop-truncation.c @@ -329,9 +329,8 @@ void test_strncpy_array (Dest *pd, int i, const char* s) of the array to NUL is not diagnosed. */ { /* This might be better written using memcpy() but it's safe so - it probably shouldn't be diagnosed. It currently triggers - a warning because of bug 81704. */ - strncpy (dst7, "0123456", sizeof dst7); /* { dg-bogus "\\\[-Wstringop-truncation]" "bug 81704" { xfail *-*-* } } */ + it shouldn't be diagnosed. */ + strncpy (dst7, "0123456", sizeof dst7); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ dst7[sizeof dst7 - 1] = '\0'; sink (dst7); } @@ -350,7 +349,7 @@ void test_strncpy_array (Dest *pd, int i, const char* s) } { - strncpy (pd->a5, "01234", sizeof pd->a5); /* { dg-bogus "\\\[-Wstringop-truncation]" "bug 81704" { xfail *-*-* } } */ + strncpy (pd->a5, "01234", sizeof pd->a5); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ pd->a5[sizeof pd->a5 - 1] = '\0'; sink (pd); } diff --git a/gcc/testsuite/gcc.dg/Wstringop-truncation-5.c b/gcc/testsuite/gcc.dg/Wstringop-truncation-5.c new file mode 100644 index 0000000..dbb5e1f --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-truncation-5.c @@ -0,0 +1,128 @@ +/* PR tree-optimization/87028 - false positive -Wstringop-truncation + strncpy with global variable source string + { dg-do compile } + { dg-options "-O2 -Wstringop-truncation" } */ + +char *strncpy (char *, const char *, __SIZE_TYPE__); + +#define STR "1234567890" + +struct S +{ + char a[5], b[5]; +}; + +const char arr[] = STR; +const char* const ptr = STR; + +const char arr2[][10] = { "123", STR }; + +void test_literal (struct S *s) +{ + strncpy (s->a, STR, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a[sizeof s->a - 1] = '\0'; +} + +void test_global_arr (struct S *s) +{ + strncpy (s->a, arr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_global_arr2 (struct S *s) +{ + strncpy (s->a, arr2[1], sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; + + strncpy (s->b, arr2[0], sizeof s->a - 1); +} + +void test_global_ptr (struct S *s) +{ + strncpy (s->a, ptr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_local_arr (struct S *s) +{ + const char arr[] = STR; + strncpy (s->a, arr, sizeof s->a - 1); + s->a [sizeof s->a - 1] = '\0'; +} + +void test_local_ptr (struct S *s) +{ + const char* const ptr = STR; + strncpy (s->a, ptr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_compound_literal (struct S *s) +{ + strncpy (s->a, (char[]){ STR }, sizeof s->a - 1); + s->a [sizeof s->a - 1] = '\0'; +} +/* PR tree-optimization/87028 - false positive -Wstringop-truncation + strncpy with global variable source string + { dg-do compile } + { dg-options "-O2 -Wstringop-truncation" } */ + +char *strncpy (char *, const char *, __SIZE_TYPE__); + +#define STR "1234567890" + +struct S +{ + char a[5], b[5]; +}; + +const char arr[] = STR; +const char* const ptr = STR; + +const char arr2[][10] = { "123", STR }; + +void test_literal (struct S *s) +{ + strncpy (s->a, STR, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a[sizeof s->a - 1] = '\0'; +} + +void test_global_arr (struct S *s) +{ + strncpy (s->a, arr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_global_arr2 (struct S *s) +{ + strncpy (s->a, arr2[1], sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; + + strncpy (s->b, arr2[0], sizeof s->a - 1); +} + +void test_global_ptr (struct S *s) +{ + strncpy (s->a, ptr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_local_arr (struct S *s) +{ + const char arr[] = STR; + strncpy (s->a, arr, sizeof s->a - 1); + s->a [sizeof s->a - 1] = '\0'; +} + +void test_local_ptr (struct S *s) +{ + const char* const ptr = STR; + strncpy (s->a, ptr, sizeof s->a - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ + s->a [sizeof s->a - 1] = '\0'; +} + +void test_compound_literal (struct S *s) +{ + strncpy (s->a, (char[]){ STR }, sizeof s->a - 1); + s->a [sizeof s->a - 1] = '\0'; +} diff --git a/gcc/testsuite/gcc.dg/fold-bcopy.c b/gcc/testsuite/gcc.dg/fold-bcopy.c index ed6cd06..9a54484 100644 --- a/gcc/testsuite/gcc.dg/fold-bcopy.c +++ b/gcc/testsuite/gcc.dg/fold-bcopy.c @@ -1,6 +1,6 @@ /* PR tree-optimization/80933 - redundant bzero/bcopy calls not eliminated { dg-do compile } - { dg-options "-O0 -Wall -fdump-tree-gimple" } */ + { dg-options "-O1 -Wall -fdump-tree-lower" } */ void f0 (void *dst, const void *src, unsigned n) { @@ -46,9 +46,9 @@ void f6 (void *p) /* Verify that calls to bcmp, bcopy, and bzero have all been removed and one of each replaced with memcmp, memmove, and memset, respectively. The remaining three should be eliminated. - { dg-final { scan-tree-dump-not "bcmp|bcopy|bzero" "gimple" } } - { dg-final { scan-tree-dump-times "memcmp|memmove|memset" 3 "gimple" } } + { dg-final { scan-tree-dump-not "bcmp|bcopy|bzero" "lower" } } + { dg-final { scan-tree-dump-times "memcmp|memmove|memset" 3 "lower" } } Verify that the bcopy to memmove transformation correctly transposed the source and destination pointer arguments. - { dg-final { scan-tree-dump-times "memmove \\(dst, src" 1 "gimple" } } */ + { dg-final { scan-tree-dump-times "memmove \\(dst, src" 1 "lower" } } */ diff --git a/gcc/testsuite/gcc.dg/strcmpopt_1.c b/gcc/testsuite/gcc.dg/strcmpopt_1.c index 40596a2..b1e0bc3 100644 --- a/gcc/testsuite/gcc.dg/strcmpopt_1.c +++ b/gcc/testsuite/gcc.dg/strcmpopt_1.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-options "-fdump-tree-gimple" } */ +/* { dg-options "-fdump-tree-lower" } */ #include <string.h> #include <stdlib.h> @@ -25,4 +25,4 @@ int main () return 0; } -/* { dg-final { scan-tree-dump-times "strcmp \\(" 2 "gimple" } } */ +/* { dg-final { scan-tree-dump-times "strcmp \\(" 2 "lower" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c index fc3580e..973ec0d 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-gimple -fdump-tree-cddce-details -fdump-tree-optimized" } */ +/* { dg-options "-O2 -fdump-tree-lower -fdump-tree-cddce-details -fdump-tree-optimized" } */ void f(void) { @@ -18,4 +18,4 @@ void h(void) /* { dg-final { scan-tree-dump "Deleting : __builtin_strdup" "cddce1" } } */ /* { dg-final { scan-tree-dump "Deleting : __builtin_strndup" "cddce1" } } */ -/* { dg-final { scan-tree-dump "__builtin_malloc" "gimple" } } */ +/* { dg-final { scan-tree-dump "__builtin_malloc" "lower" } } */ |