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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [strlenopt-13.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)) void
7
fn1 (char *p, const char *y, const char *z, size_t *lp)
8
{
9
  char *q, *r, *s;
10
  char buf1[64], buf2[64];
11
  size_t l[8];
12
  /* These two strlen calls stay, all strcpy calls are optimized into
13
     memcpy, all strchr calls optimized away, and most other strlen
14
     calls too.  */
15
  l[0] = strlen (y);
16
  l[1] = strlen (z);
17
  strcpy (buf1, y);
18
  strcpy (buf2, z);
19
  strcpy (p, "abcde");
20
  q = strchr (p, '\0');
21
  strcpy (q, "efghi");
22
  r = strchr (q, '\0');
23
  strcpy (r, buf1);
24
  l[2] = strlen (p);
25
  l[3] = strlen (q);
26
  l[4] = strlen (r);
27
  strcpy (r, buf2);
28
  /* Except for these two calls, strlen (r) before and after the above
29
     is non-constant, so adding l[4] - l[1] to all previous strlens
30
     might make the expressions already too complex.  */
31
  l[5] = strlen (p);
32
  l[6] = strlen (q);
33
  /* This one is of course optimized, it is l[1].  */
34
  l[7] = strlen (r);
35
  memcpy (lp, l, sizeof l);
36
}
37
 
38
int
39
main ()
40
{
41
  char buf[64];
42
  size_t l[8];
43
  const char *volatile y = "ABCDEFG";
44
  const char *volatile z = "HIJK";
45
  memset (buf, '\0', sizeof buf);
46
  fn1 (buf, y, z, l);
47
  if (memcmp (buf, "abcdeefghiHIJK", 15) != 0)
48
    abort ();
49
  if (l[0] != 7 || l[1] != 4)
50
    abort ();
51
  if (l[2] != 17 || l[3] != 12 || l[4] != 7)
52
    abort ();
53
  if (l[5] != 14 || l[6] != 9 || l[7] != 4)
54
    abort ();
55
  return 0;
56
}
57
 
58
/* { dg-final { scan-tree-dump-times "strlen \\(" 4 "strlen" } } */
59
/* { dg-final { scan-tree-dump-times "memcpy \\(" 7 "strlen" } } */
60
/* { dg-final { scan-tree-dump-times "strcpy \\(" 0 "strlen" } } */
61
/* { dg-final { scan-tree-dump-times "strcat \\(" 0 "strlen" } } */
62
/* { dg-final { scan-tree-dump-times "strchr \\(" 0 "strlen" } } */
63
/* { dg-final { scan-tree-dump-times "stpcpy \\(" 0 "strlen" } } */
64
/* { dg-final { scan-tree-dump-times "  D\.\[0-9_\]* = strlen \\(\[^\n\r\]*;\[\n\r\]*  l.0. = " 1 "strlen" } } */
65
/* { dg-final { scan-tree-dump-times "  D\.\[0-9_\]* = strlen \\(\[^\n\r\]*;\[\n\r\]*  l.1. = " 1 "strlen" } } */
66
/* { dg-final { scan-tree-dump-times "  D\.\[0-9_\]* = strlen \\(\[^\n\r\]*;\[\n\r\]*  l.5. = " 1 "strlen" } } */
67
/* { dg-final { scan-tree-dump-times "  D\.\[0-9_\]* = strlen \\(\[^\n\r\]*;\[\n\r\]*  l.6. = " 1 "strlen" } } */
68
/* { 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.