| 1 |
/* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */ |
| 2 |
/* { dg-options "-O2 -fdump-tree-strlen" } */ |
| 3 |
|
| 4 |
#define USE_GNU |
| 5 |
#include "strlenopt.h" |
| 6 |
|
| 7 |
volatile int v; |
| 8 |
|
| 9 |
size_t __attribute__ ((noinline, noclone)) |
| 10 |
f1 (char *b) |
| 11 |
{ |
| 12 |
char a[30]; |
| 13 |
v += 1; |
| 14 |
// Should be converted to stpcpy. |
| 15 |
strcpy (a, b); |
| 16 |
int len1 = strlen (a); |
| 17 |
a[0] = '_'; |
| 18 |
a[1] = 0; |
| 19 |
return len1 + strlen (a); |
| 20 |
} |
| 21 |
|
| 22 |
size_t __attribute__ ((noinline, noclone)) |
| 23 |
f2 (char *a, char *b) |
| 24 |
{ |
| 25 |
v += 2; |
| 26 |
// Should be converted to stpcpy. |
| 27 |
strcpy (a, b); |
| 28 |
int len1 = strlen (a); |
| 29 |
a[0] = '_'; |
| 30 |
a[1] = 0; |
| 31 |
return len1 + strlen (a); |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main () |
| 36 |
{ |
| 37 |
char a[30]; |
| 38 |
if (f1 ("foo") != 4 || f2 (a, "foobar") != 7) |
| 39 |
abort (); |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen1" } } */ |
| 44 |
/* { dg-final { scan-tree-dump-times "stpcpy \\(" 2 "strlen1" } } */ |