diff options
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index cfae9db..fadc422 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -1899,6 +1899,11 @@ gimple_fold_builtin_strchr (gimple_stmt_iterator *gsi, bool is_strrchr) if (!gimple_call_lhs (stmt)) return false; + /* Avoid folding if the first argument is not a nul-terminated array. + Defer warning until later. */ + if (!check_nul_terminated_array (NULL_TREE, str)) + return false; + if ((p = c_getstr (str)) && target_char_cst_p (c, &ch)) { const char *p1 = is_strrchr ? strrchr (p, ch) : strchr (p, ch); @@ -1973,18 +1978,23 @@ static bool gimple_fold_builtin_strstr (gimple_stmt_iterator *gsi) { gimple *stmt = gsi_stmt (*gsi); + if (!gimple_call_lhs (stmt)) + return false; + tree haystack = gimple_call_arg (stmt, 0); tree needle = gimple_call_arg (stmt, 1); - const char *p, *q; - if (!gimple_call_lhs (stmt)) + /* Avoid folding if either argument is not a nul-terminated array. + Defer warning until later. */ + if (!check_nul_terminated_array (NULL_TREE, haystack) + || !check_nul_terminated_array (NULL_TREE, needle)) return false; - q = c_getstr (needle); + const char *q = c_getstr (needle); if (q == NULL) return false; - if ((p = c_getstr (haystack))) + if (const char *p = c_getstr (haystack)) { const char *r = strstr (p, q); |