2 /* { dg-options "-O2 -fdump-tree-strlen" } */
6 __attribute__((noinline
, noclone
)) size_t
7 fn1 (char *p
, size_t l
)
9 memcpy (p
, "abcdef", l
);
10 /* This strlen can't be optimized, as l is unknown. */
14 __attribute__((noinline
, noclone
)) size_t
15 fn2 (char *p
, const char *q
, size_t *lp
)
17 size_t l
= strlen (q
), l2
;
19 /* This strlen can't be optimized, as l might be bigger than 7. */
25 __attribute__((noinline
, noclone
)) char *
36 const char *volatile q
= "ABCDEFGH";
37 const char *volatile q2
= "IJ\0KLMNOPQRS";
39 memset (buf
, '\0', sizeof buf
);
40 memset (buf
+ 2, 'a', 7);
41 if (fn1 (buf
, 3) != 9 || memcmp (buf
, "abcaaaaaa", 10) != 0)
43 if (fn1 (buf
, 7) != 6 || memcmp (buf
, "abcdef\0aa", 10) != 0)
45 if (fn2 (buf
, q
, &l
) != 9 || l
!= 8 || memcmp (buf
, "ABCDEFGaa", 10) != 0)
47 if (fn2 (buf
, q2
, &l
) != 2 || l
!= 2 || memcmp (buf
, "IJ\0KLMNaa", 10) != 0)
49 if (fn3 (buf
) != buf
+ 1 || memcmp (buf
, "\0J\0KLMNaa", 10) != 0)
54 /* { dg-final { scan-tree-dump-times "strlen \\(" 3 "strlen" } } */
55 /* { dg-final { scan-tree-dump-times "memcpy \\(" 2 "strlen" } } */
56 /* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
57 /* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
58 /* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
59 /* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
60 /* { dg-final { cleanup-tree-dump "strlen" } } */