From: Bernd Edlinger Date: Tue, 21 Aug 2018 08:56:11 +0000 (+0000) Subject: re PR middle-end/86121 (missing -Wstringop-overflow on strcpy followed by strcat) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7d4ae1fbbf162289ad27490899dafc6747f18800;p=gcc.git re PR middle-end/86121 (missing -Wstringop-overflow on strcpy followed by strcat) 2018-08-21 Bernd Edlinger PR middle-end/86121 * tree-ssa-strlen.c (adjust_last_stmt): Avoid folding away undefined behaviour. testsuite: 2018-08-21 Bernd Edlinger PR middle-end/86121 * gcc.dg/Wstringop-overflow-6.c: Remove xfail. From-SVN: r263693 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 041b4f85a26..b4b7fe0b27e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-08-21 Bernd Edlinger + + PR middle-end/86121 + * tree-ssa-strlen.c (adjust_last_stmt): Avoid folding away undefined + behaviour. + 2018-08-21 Rasmus Villemoes * config/vxworks.h: Guard vxworks_asm_out_constructor and diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0a420304716..eb143b3fa7a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-21 Bernd Edlinger + + PR middle-end/86121 + * gcc.dg/Wstringop-overflow-6.c: Remove xfail. + 2018-08-21 Tom de Vries * gcc.c-torture/unsorted/dump-noaddr.x: Use -gno-record-gcc-switches diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c index 9284a87aeb0..acb0fcb6dc7 100644 --- a/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-6.c @@ -25,7 +25,7 @@ void test_strcpy_strcat_1 (void) void test_strcpy_strcat_2 (void) { - strcpy (a2, "12"), strcat (a2, "3"); /* { dg-warning "\\\[-Wstringop-overflow=]" "bug 86121" { xfail *-*-* } } */ + strcpy (a2, "12"), strcat (a2, "3"); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ } void test_strcpy_strcat_3 (void) diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 1d813b46867..d0792aa38c8 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1107,6 +1107,13 @@ adjust_last_stmt (strinfo *si, gimple *stmt, bool is_strcat) to store the extra '\0' in that case. */ if ((tree_to_uhwi (len) & 3) == 0) return; + + /* Don't fold away an out of bounds access, as this defeats proper + warnings. */ + tree dst = gimple_call_arg (last.stmt, 0); + tree size = compute_objsize (dst, 0); + if (size && tree_int_cst_lt (size, len)) + return; } else if (TREE_CODE (len) == SSA_NAME) {