OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [strlenopt-2.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 689 jeremybenn
/* { dg-do run } */
2
/* { dg-options "-O2 -fdump-tree-strlen" } */
3
 
4
#include "strlenopt.h"
5
 
6
__attribute__((noinline, noclone)) char *
7
foo (char *p, char *r)
8
{
9
  char buf[26];
10
  if (strlen (p) + strlen (r) + 9 > 26)
11
    return NULL;
12
  /* This strcpy can be optimized into memcpy, using the remembered
13
     strlen (p).  */
14
  strcpy (buf, p);
15
  /* These two strcat can be optimized into memcpy.  The first one
16
     could be even optimized into a *ptr = '/'; store as the '\0'
17
     is immediately overwritten.  */
18
  strcat (buf, "/");
19
  strcat (buf, "abcde");
20
  /* This strcpy can be optimized into memcpy, using the remembered
21
     strlen (r).  */
22
  strcat (buf, r);
23
  /* And this can be optimized into memcpy too.  */
24
  strcat (buf, "fg");
25
  return strdup (buf);
26
}
27
 
28
int
29
main ()
30
{
31
  char *volatile p = "string1";
32
  char *volatile r = "string2";
33
  char *q = foo (p, r);
34
  if (q != NULL)
35
    {
36
      if (strcmp (q, "string1/abcdestring2fg"))
37
        abort ();
38
      free (q);
39
    }
40
  return 0;
41
}
42
 
43
/* { dg-final { scan-tree-dump-times "strlen \\(" 2 "strlen" } } */
44
/* { dg-final { scan-tree-dump-times "memcpy \\(" 5 "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 { cleanup-tree-dump "strlen" } } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.