PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-16g.c
blob0cf8410735a9e3a2f5d3bd22e283e40e8f7228e4
1 /* This test needs runtime that provides stpcpy function. */
2 /* { dg-do run { target *-*-linux* *-*-gnu* } } */
3 /* { dg-options "-O2 -fdump-tree-strlen" } */
5 #define USE_GNU
6 #include "strlenopt.h"
8 __attribute__((noinline, noclone)) char *
9 fn1 (char *p, const char *q)
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');
17 int
18 main ()
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;
27 /* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen" } } */
28 /* { dg-final { scan-tree-dump-times "memcpy \\(" 0 "strlen" } } */
29 /* { dg-final { scan-tree-dump-times "mempcpy \\(" 0 "strlen" } } */
30 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
31 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
32 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
33 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 1 "strlen" } } */