From: Jakub Jelinek Date: Fri, 30 Aug 2019 12:18:54 +0000 (+0200) Subject: backport: re PR tree-optimization/89703 (ICE in compare_values_warnv, at tree-vrp... X-Git-Tag: releases/gcc-7.5.0~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15a04f92b313735a4f105f4a3b3ddec2098aa057;p=thirdparty%2Fgcc.git backport: re PR tree-optimization/89703 (ICE in compare_values_warnv, at tree-vrp.c:997) Backported from mainline 2019-03-14 Jakub Jelinek PR tree-optimization/89703 * tree-ssa-strlen.c (valid_builtin_call): Punt if stmt call types aren't compatible also with builtin_decl_explicit. Check pure or non-pure status of BUILT_IN_STR{{,N}CMP,N{LEN,{CAT,CPY}{,_CHK}}} and BUILT_IN_STPNCPY{,_CHK}. * gcc.c-torture/compile/pr89703-1.c: New test. * gcc.c-torture/compile/pr89703-2.c: New test. From-SVN: r275131 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a60a54e8ffc6..1be99eebeef2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,14 @@ 2019-08-30 Jakub Jelinek Backported from mainline + 2019-03-14 Jakub Jelinek + + PR tree-optimization/89703 + * tree-ssa-strlen.c (valid_builtin_call): Punt if stmt call types + aren't compatible also with builtin_decl_explicit. Check pure + or non-pure status of BUILT_IN_STR{{,N}CMP,N{LEN,{CAT,CPY}{,_CHK}}} + and BUILT_IN_STPNCPY{,_CHK}. + 2019-03-13 Jakub Jelinek PR middle-end/88588 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 647648521364..e5525de68184 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,10 @@ Backported from mainline 2019-03-14 Jakub Jelinek + PR tree-optimization/89703 + * gcc.c-torture/compile/pr89703-1.c: New test. + * gcc.c-torture/compile/pr89703-2.c: New test. + PR c++/89512 * g++.dg/cpp1y/var-templ61.C: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr89703-1.c b/gcc/testsuite/gcc.c-torture/compile/pr89703-1.c new file mode 100644 index 000000000000..958cc7744e1f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr89703-1.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/89703 */ + +typedef __SIZE_TYPE__ size_t; +extern char *strlen (const char *); +extern char *strnlen (const char *, size_t); +extern char c[2]; + +void +foo (char **q) +{ + q[0] = strlen (c); + q[1] = strnlen (c, 2); +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr89703-2.c b/gcc/testsuite/gcc.c-torture/compile/pr89703-2.c new file mode 100644 index 000000000000..d2676ded0cae --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr89703-2.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/89703 */ + +typedef __SIZE_TYPE__ size_t; +extern void *memcpy (void *, const void *, size_t); +extern char *strlen (const char *); +extern char c[2]; + +void +foo (char **q) +{ + memcpy (c, "a", 2); + q[0] = strlen (c); +} diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index f9f2fdd68f00..6fd6122375f7 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -936,10 +936,18 @@ valid_builtin_call (gimple *stmt) return false; tree callee = gimple_call_fndecl (stmt); + tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (callee)); + if (decl + && decl != callee + && !gimple_builtin_call_types_compatible_p (stmt, decl)) + return false; + switch (DECL_FUNCTION_CODE (callee)) { case BUILT_IN_MEMCMP: case BUILT_IN_MEMCMP_EQ: + case BUILT_IN_STRCMP: + case BUILT_IN_STRNCMP: case BUILT_IN_STRCHR: case BUILT_IN_STRCHR_CHKP: case BUILT_IN_STRLEN: @@ -964,6 +972,8 @@ valid_builtin_call (gimple *stmt) case BUILT_IN_STPCPY_CHK: case BUILT_IN_STPCPY_CHKP: case BUILT_IN_STPCPY_CHK_CHKP: + case BUILT_IN_STPNCPY: + case BUILT_IN_STPNCPY_CHK: case BUILT_IN_STRCAT: case BUILT_IN_STRCAT_CHK: case BUILT_IN_STRCAT_CHKP: @@ -972,6 +982,10 @@ valid_builtin_call (gimple *stmt) case BUILT_IN_STRCPY_CHK: case BUILT_IN_STRCPY_CHKP: case BUILT_IN_STRCPY_CHK_CHKP: + case BUILT_IN_STRNCAT: + case BUILT_IN_STRNCAT_CHK: + case BUILT_IN_STRNCPY: + case BUILT_IN_STRNCPY_CHK: /* The above functions should be neither const nor pure. Punt if they aren't. */ if (gimple_vdef (stmt) == NULL_TREE || gimple_vuse (stmt) == NULL_TREE)