2 /* { dg-options "-O2 -fdump-tree-strlen -fdump-tree-optimized" } */
8 __attribute__((noinline
, noclone
)) size_t
11 char *p
= memcpy (buf
, "abcdefgh", 9);
12 /* This store can be optimized away as... */
14 /* ... the following strcat can be optimized into memcpy,
15 which overwrites that '\0'. */
17 /* This should be optimized into return 3. */
21 __attribute__((noinline
, noclone
)) size_t
24 char *r
= strchr (p
, '\0');
25 /* This store shouldn't be optimized away, because we
26 want to crash if p is e.g. a string literal. */
28 /* This strlen can be optimized into 0. */
35 char *volatile p
= buf
;
36 if (foo () != 3 || memcmp (buf
, "ijk\0efgh\0", 10) != 0)
38 if (bar (p
) != 0 || memcmp (buf
, "ijk\0efgh\0", 10) != 0)
43 /* { dg-final { scan-tree-dump-times "strlen \\(" 1 "strlen" } } */
44 /* { dg-final { scan-tree-dump-times "memcpy \\(" 2 "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" } } */
49 /* { dg-final { scan-tree-dump-times "\\*r_\[0-9\]* = 0;" 1 "strlen" } } */
50 /* { dg-final { scan-tree-dump-times "return 3;" 1 "optimized" } } */
51 /* { dg-final { scan-tree-dump-times "return 0;" 2 "optimized" } } */