diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-03-14 09:56:47 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-03-14 09:56:47 +0100 |
commit | f54e63dfa34c4c9922a4cb35d2f8c28c92135b8c (patch) | |
tree | dcc71073887e0245bfb6407a7399670aa794b8dc /gcc | |
parent | fb055f4b745b1b56d84ad920508ebed2d22d3616 (diff) | |
download | gcc-f54e63dfa34c4c9922a4cb35d2f8c28c92135b8c.zip gcc-f54e63dfa34c4c9922a4cb35d2f8c28c92135b8c.tar.gz gcc-f54e63dfa34c4c9922a4cb35d2f8c28c92135b8c.tar.bz2 |
re PR tree-optimization/89703 (ICE in compare_values_warnv, at tree-vrp.c:997)
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: r269674
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr89703-1.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/pr89703-2.c | 13 | ||||
-rw-r--r-- | gcc/tree-ssa-strlen.c | 15 |
5 files changed, 55 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 927fd9e..8c3a6b9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-03-14 Jakub Jelinek <jakub@redhat.com> + + 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-14 H.J. Lu <hongjiu.lu@intel.com> PR target/89523 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0776c67..db45dc4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-14 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/89703 + * gcc.c-torture/compile/pr89703-1.c: New test. + * gcc.c-torture/compile/pr89703-2.c: New test. + 2019-03-14 H.J. Lu <hongjiu.lu@intel.com> PR target/89523 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 0000000..958cc77 --- /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 0000000..d2676de --- /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 721832e..1eaed66 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -971,12 +971,21 @@ 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_STRLEN: + case BUILT_IN_STRNLEN: /* The above functions should be pure. Punt if they aren't. */ if (gimple_vdef (stmt) || gimple_vuse (stmt) == NULL_TREE) return false; @@ -991,10 +1000,16 @@ valid_builtin_call (gimple *stmt) case BUILT_IN_MEMSET: case BUILT_IN_STPCPY: case BUILT_IN_STPCPY_CHK: + case BUILT_IN_STPNCPY: + case BUILT_IN_STPNCPY_CHK: case BUILT_IN_STRCAT: case BUILT_IN_STRCAT_CHK: case BUILT_IN_STRCPY: case BUILT_IN_STRCPY_CHK: + 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) |