aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const-call.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2016-12-07 20:45:45 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2016-12-07 20:45:45 +0100
commitc89529306c91eafa81c762e9050d51c747c14af0 (patch)
treebd3017b456fa1faec07937e6000fdcee0fa4895e /gcc/fold-const-call.c
parent77f1efdbe8fe401040adb9b2b43aac85916682ac (diff)
downloadgcc-c89529306c91eafa81c762e9050d51c747c14af0.zip
gcc-c89529306c91eafa81c762e9050d51c747c14af0.tar.gz
gcc-c89529306c91eafa81c762e9050d51c747c14af0.tar.bz2
builtins.c (fold_builtin_strstr): Removed.
* builtins.c (fold_builtin_strstr): Removed. (fold_builtin_2): Don't call fold_builtin_strstr. * gimple-fold.c (gimple_fold_builtin_strchr): Check is_strrchr earlier in the strrchr (x, 0) -> strchr (x, 0) optimization. (gimple_fold_builtin_strstr): New function. (gimple_fold_builtin): Call it. * fold-const-call.c (fold_const_call): Handle CFN_BUILT_IN_STRSTR. * gcc.dg/builtin-strstr-1.c: New test. * g++.dg/cpp0x/constexpr-strstr.C: New test. From-SVN: r243378
Diffstat (limited to 'gcc/fold-const-call.c')
-rw-r--r--gcc/fold-const-call.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c
index c85fb41..f978da3 100644
--- a/gcc/fold-const-call.c
+++ b/gcc/fold-const-call.c
@@ -1434,6 +1434,22 @@ fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1)
}
return NULL_TREE;
+ case CFN_BUILT_IN_STRSTR:
+ if ((p1 = c_getstr (arg1)))
+ {
+ if ((p0 = c_getstr (arg0)))
+ {
+ const char *r = strstr (p0, p1);
+ if (r == NULL)
+ return build_int_cst (type, 0);
+ return fold_convert (type,
+ fold_build_pointer_plus_hwi (arg0, r - p0));
+ }
+ if (*p1 == '\0')
+ return fold_convert (type, arg0);
+ }
+ return NULL_TREE;
+
default:
return fold_const_call_1 (fn, type, arg0, arg1);
}