diff options
author | Martin Sebor <msebor@redhat.com> | 2018-06-12 18:05:13 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-06-12 12:05:13 -0600 |
commit | e3329a782fc0e51b9a4ddfc6938a484ec4b03084 (patch) | |
tree | 54f2c40c75f1eaadb4e09b9210721c95bda1b3a4 /gcc/testsuite/gcc.dg/Wstringop-overflow-6.c | |
parent | 47feeb36526b106053ad8d4fc7a64c23ce16f5de (diff) | |
download | gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.zip gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.gz gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.bz2 |
PR tree-optimization/85259 - Missing -Wstringop-overflow= since r256683
gcc/ChangeLog:
PR tree-optimization/85259
* builtins.c (compute_objsize): Handle constant offsets.
* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Return
true iff a warning has been issued.
* gimple.h (gimple_nonartificial_location): New function.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Call
gimple_nonartificial_location and handle -Wno-system-headers.
(handle_builtin_stxncpy): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/85259
* gcc.dg/Wstringop-overflow-5.c: New test.
* gcc.dg/Wstringop-overflow-6.c: New test.
From-SVN: r261518
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wstringop-overflow-6.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Wstringop-overflow-6.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c new file mode 100644 index 0000000..9284a87 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c @@ -0,0 +1,59 @@ +/* PR tree-optimization/85259 - Missing -Wstringop-overflow= since r256683 + { dg-do compile } + { dg-options "-O2 -Wstringop-overflow -ftrack-macro-expansion=0" } */ + +#define bos1(p) __builtin_object_size (p, 1) +#define strcat(d, s) __builtin___strcat_chk (d, s, bos1 (d)) +#define strcpy(d, s) __builtin___strcpy_chk (d, s, bos1 (d)) + +char a1[1]; +char a2[2]; +char a3[3]; +char a4[4]; +char a5[5]; +char a6[6]; +char a7[7]; +char a8[8]; + +/* Verify that at least one instance of -Wstringop-overflow is issued + for each pair of strcpy/strcat calls. */ + +void test_strcpy_strcat_1 (void) +{ + strcpy (a1, "1"), strcat (a1, "2"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_2 (void) +{ + strcpy (a2, "12"), strcat (a2, "3"); /* { dg-warning "\\\[-Wstringop-overflow=]" "bug 86121" { xfail *-*-* } } */ +} + +void test_strcpy_strcat_3 (void) +{ + strcpy (a3, "123"), strcat (a3, "4"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_4 (void) +{ + strcpy (a4, "1234"), strcat (a4, "5"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_5 (void) +{ + strcpy (a5, "12345"), strcat (a5, "6"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_6 (void) +{ + strcpy (a6, "123456"), strcat (a6, "7"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_7 (void) +{ + strcpy (a7, "1234567"), strcat (a7, "8"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} + +void test_strcpy_strcat_8 (void) +{ + strcpy (a8, "12345678"), strcat (a8, "9"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ +} |