2017-12-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-5.c
bloba24aea44e8b00ff7b35a907aaa941b4c509642c4
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-strlen" } */
4 #include "strlenopt.h"
6 __attribute__((noinline, noclone)) char *
7 foo (char *p, const char *q)
9 char *e = strchr (p, '\0');
10 strcat (p, q);
11 return e;
14 __attribute__((noinline, noclone)) char *
15 bar (char *p)
17 memcpy (p, "abcd", 5);
18 return strchr (p, '\0');
21 __attribute__((noinline, noclone)) void
22 baz (char *p)
24 char *e = strchr (p, '\0');
25 strcat (e, "abcd");
28 char buf[64];
30 int
31 main ()
33 char *volatile p = buf;
34 const char *volatile q = "ij";
35 memset (buf, 'v', 3);
36 if (foo (p, q) != buf + 3
37 || memcmp (buf, "vvvij\0\0\0\0", 10) != 0)
38 abort ();
39 memset (buf, '\0', sizeof buf);
40 if (bar (p) != buf + 4
41 || memcmp (buf, "abcd\0\0\0\0\0", 10) != 0)
42 abort ();
43 memset (buf, 'v', 2);
44 memset (buf + 2, '\0', -2 + sizeof buf);
45 baz (p);
46 if (memcmp (buf, "vvabcd\0\0\0", 10) != 0)
47 abort ();
48 return 0;
51 /* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
52 /* { dg-final { scan-tree-dump-times "memcpy \\(" 2 "strlen" } } */
53 /* { dg-final { scan-tree-dump-times "strcpy \\(" 1 "strlen" } } */
54 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
55 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
56 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */