diff options
author | Martin Sebor <msebor@redhat.com> | 2019-11-26 23:56:22 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-11-26 16:56:22 -0700 |
commit | d86d8b35ddec33371cf2efaa05dfeffe035babbe (patch) | |
tree | 0e6e859da945b4aa63f8da56da2c3774068d8e62 /gcc/gimple-fold.c | |
parent | e4c935cb98add40d0a6350a798a8258951dfc9d9 (diff) | |
download | gcc-d86d8b35ddec33371cf2efaa05dfeffe035babbe.zip gcc-d86d8b35ddec33371cf2efaa05dfeffe035babbe.tar.gz gcc-d86d8b35ddec33371cf2efaa05dfeffe035babbe.tar.bz2 |
PR tree-optimization/92683 - strncmp incorrect result with equal substrings and non-const bound
gcc/testsuite/ChangeLog:
PR tree-optimization/92683
* gcc.dg/strcmpopt_8.c: New test.
* gcc.dg/strcmpopt_9.c: New test.
gcc/ChangeLog:
PR tree-optimization/92683
* gimple-fold.c (gimple_fold_builtin_string_compare): Restore a test
inadvertently removed in a previous change. Rename local variable
for clarity.
From-SVN: r278742
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index fadc422..849bee2 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -2346,18 +2346,19 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi) tree str1 = gimple_call_arg (stmt, 0); tree str2 = gimple_call_arg (stmt, 1); tree lhs = gimple_call_lhs (stmt); - tree len = NULL_TREE; + + tree bound_node = NULL_TREE; unsigned HOST_WIDE_INT bound = HOST_WIDE_INT_M1U; /* Handle strncmp and strncasecmp functions. */ if (gimple_call_num_args (stmt) == 3) { - len = gimple_call_arg (stmt, 2); - if (tree_fits_uhwi_p (len)) - bound = tree_to_uhwi (len); + bound_node = gimple_call_arg (stmt, 2); + if (tree_fits_uhwi_p (bound_node)) + bound = tree_to_uhwi (bound_node); } - /* If the LEN parameter is zero, return zero. */ + /* If the BOUND parameter is zero, return zero. */ if (bound == 0) { replace_call_with_value (gsi, integer_zero_node); @@ -2418,6 +2419,9 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi) case BUILT_IN_STRNCMP: case BUILT_IN_STRNCMP_EQ: { + if (bound == HOST_WIDE_INT_M1U) + break; + /* Reduce the bound to be no more than the length of the shorter of the two strings, or the sizes of the unterminated arrays. */ |