aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/strlenopt-33g.c
blob: 195000832466e808a8c690fbe9bac86c236890f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* { dg-do run { target *-*-linux* *-*-gnu* *-*-uclinux* } } */
/* { dg-options "-O2 -fdump-tree-strlen" } */

#define USE_GNU
#include "strlenopt.h"

volatile int v;

size_t __attribute__ ((noinline, noclone))
f1 (char *b)
{
  char a[30];
  v += 1;
  // Should be converted to stpcpy.
  strcpy (a, b);
  int len1 = strlen (a);
  a[0] = '_';
  a[1] = 0;
  return len1 + strlen (a);
}

size_t __attribute__ ((noinline, noclone))
f2 (char *a, char *b)
{
  v += 2;
  // Should be converted to stpcpy.
  strcpy (a, b);
  int len1 = strlen (a);
  a[0] = '_';
  a[1] = 0;
  return len1 + strlen (a);
}

int
main ()
{
  char a[30];
  if (f1 ("foo") != 4 || f2 (a, "foobar") != 7)
    abort ();
  return 0;
}

/* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen1" } } */
/* { dg-final { scan-tree-dump-times "stpcpy \\(" 2 "strlen1" } } */