1 /* This test needs runtime that provides stpcpy function. */
2 /* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */
3 /* { dg-options "-O2 -fdump-tree-strlen" } */
4
5 #define USE_GNU
6 #include "strlenopt.h"
7
8 __attribute__((noinline, noclone)) char *
9 fn1 (char *p, const char *q)
10 {
11 /* This strcpy can be optimized into stpcpy. */
12 strcpy (p, q);
13 /* And this strchr into the return value from it. */
14 return strchr (p, '\0');
15 }
16
17 int
18 main ()
19 {
20 char buf[64];
21 const char *volatile q = "ABCDEFGH";
22 if (fn1 (buf, q) != buf + 8 || memcmp (buf, "ABCDEFGH", 9) != 0)
23 abort ();
24 return 0;
25 }
26
27 /* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen1" } } */
28 /* { dg-final { scan-tree-dump-times "memcpy \\(" 0 "strlen1" } } */
29 /* { dg-final { scan-tree-dump-times "mempcpy \\(" 0 "strlen1" } } */
30 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen1" } } */
31 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen1" } } */
32 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen1" } } */
33 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 1 "strlen1" } } */