2 /* { dg-options "-O2 -fdump-tree-strlen" } */
6 __attribute__((noinline
, noclone
)) char *
10 /* Once PTA is fixed, we'll need just one strlen here,
11 without the memcpy. */
13 char *q
= malloc (strlen (p
) + 64);
15 /* This is here just because PTA can't figure that
16 *q = '\0' store below can't change p's length.
17 In this case we have one strlen and one memcpy here. */
19 char *q
= malloc (strlen (x
) + 64);
20 char *p
= strcpy (b
, x
);
23 if (q
== NULL
) return NULL
;
24 /* This store can be optimized away once strcat is
25 replaced with memcpy. */
27 /* These two strcat calls can be optimized into memcpy calls. */
30 /* The strchr can be optimized away, as we know the current
31 string length as well as end pointer. */
33 /* This store can go, as it is overwriting '\0' with the same
36 /* And this strcat can be again optimized into memcpy call. */
41 __attribute__((noinline
, noclone
)) char *
46 if (strlen (p
) + 9 > 26)
51 r
= strchr (buf
, '\0');
53 strcat (buf
, "abcde");
60 char *volatile p
= "string1";
61 char *volatile r
= "string2";
65 if (strcmp (q
, "string1/abcde"))
73 if (strcmp (q
, "string1/abcde"))
80 /* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
81 /* { dg-final { scan-tree-dump-times "memcpy \\(" 7 "strlen" } } */
82 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
83 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
84 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
85 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */