From b631bdb3c16e85f35d38e39b3d315c35e4a5747c Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 25 Jul 2019 00:29:17 +0000 Subject: 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 --- gcc/builtins.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gcc/builtins.c') diff --git a/gcc/builtins.c b/gcc/builtins.c index e5a9261..695a9d1 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3652,6 +3652,20 @@ compute_objsize (tree dest, int ostype) if (!ostype) return NULL_TREE; + if (TREE_CODE (dest) == MEM_REF) + { + tree ref = TREE_OPERAND (dest, 0); + tree off = TREE_OPERAND (dest, 1); + if (tree size = compute_objsize (ref, ostype)) + { + if (tree_int_cst_lt (off, size)) + return fold_build2 (MINUS_EXPR, size_type_node, size, off); + return integer_zero_node; + } + + return NULL_TREE; + } + if (TREE_CODE (dest) != ADDR_EXPR) return NULL_TREE; -- cgit v1.1