* 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
13 lines
511 B
C
13 lines
511 B
C
// { dg-do compile { target c++11 } }
|
|
|
|
constexpr const char *f1 (const char *p, const char *q) { return __builtin_strstr (p, q); }
|
|
constexpr const char a[] = "abcdefedcbaaaaab";
|
|
constexpr const char b[] = "fed";
|
|
constexpr const char c[] = "aaab";
|
|
static_assert (f1 ("abcde", "ee") == nullptr, "");
|
|
static_assert (f1 (a, b) == a + 5, "");
|
|
static_assert (f1 (a, c) == a + 12, "");
|
|
static_assert (f1 (a, "") == a, "");
|
|
static_assert (f1 (a, "aaaaaab") == nullptr, "");
|
|
static_assert (f1 (a, "aaa") == a + 10, "");
|