LWG 3035. std::allocator's constructors should be constexpr
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-2.c
blobfd59a3cd513802e0d427be84eef9300c8ecbdd9f
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-strlen" } */
4 #include "strlenopt.h"
6 __attribute__((noinline, noclone)) char *
7 foo (char *p, char *r)
9 char buf[26];
10 if (strlen (p) + strlen (r) + 9 > 26)
11 return NULL;
12 /* This strcpy can be optimized into memcpy, using the remembered
13 strlen (p). */
14 strcpy (buf, p);
15 /* These two strcat can be optimized into memcpy. The first one
16 could be even optimized into a *ptr = '/'; store as the '\0'
17 is immediately overwritten. */
18 strcat (buf, "/");
19 strcat (buf, "abcde");
20 /* This strcpy can be optimized into memcpy, using the remembered
21 strlen (r). */
22 strcat (buf, r);
23 /* And this can be optimized into memcpy too. */
24 strcat (buf, "fg");
25 return strdup (buf);
28 int
29 main ()
31 char *volatile p = "string1";
32 char *volatile r = "string2";
33 char *q = foo (p, r);
34 if (q != NULL)
36 if (strcmp (q, "string1/abcdestring2fg"))
37 abort ();
38 free (q);
40 return 0;
43 /* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
44 /* { dg-final { scan-tree-dump-times "memcpy \\(" 5 "strlen" } } */
45 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
46 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
47 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
48 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */