Fix broken MinGW build of gcc.c
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-3.c
blobf17779c0a66247ef04d1cd228577956399f96332
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-strlen -fdump-tree-optimized" } */
4 #include "strlenopt.h"
6 __attribute__((noinline, noclone)) size_t
7 fn1 (char *p, char *q)
9 size_t s = strlen (q);
10 strcpy (p, q);
11 return s - strlen (p);
14 __attribute__((noinline, noclone)) size_t
15 fn2 (char *p, char *q)
17 size_t s = strlen (q);
18 memcpy (p, q, s + 1);
19 return s - strlen (p);
22 __attribute__((noinline, noclone)) size_t
23 fn3 (char *p)
25 memcpy (p, "abcd", 5);
26 return strlen (p);
29 __attribute__((noinline, noclone)) size_t
30 fn4 (char *p)
32 memcpy (p, "efg\0hij", 6);
33 return strlen (p);
36 int
37 main ()
39 char buf[64];
40 char *volatile p = buf;
41 char *volatile q = "ABCDEF";
42 buf[7] = 'G';
43 if (fn1 (p, q) != 0 || memcmp (buf, "ABCDEF\0G", 8))
44 abort ();
45 q = "HIJ";
46 if (fn2 (p + 1, q) != 0 || memcmp (buf, "AHIJ\0F\0G", 8))
47 abort ();
48 buf[6] = 'K';
49 if (fn3 (p + 1) != 4 || memcmp (buf, "Aabcd\0KG", 8))
50 abort ();
51 if (fn4 (p) != 3 || memcmp (buf, "efg\0hiKG", 8))
52 abort ();
53 return 0;
56 /* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
57 /* { dg-final { scan-tree-dump-times "memcpy \\(" 4 "strlen" } } */
58 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
59 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
60 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
61 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
62 /* { dg-final { scan-tree-dump-times "return 0" 3 "optimized" } } */
63 /* { dg-final { scan-tree-dump-times "return 4" 1 "optimized" } } */
64 /* { dg-final { scan-tree-dump-times "return 3" 1 "optimized" } } */