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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [pr17377.c] - Blame information for rev 801

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

Line No. Rev Author Line
1 688 jeremybenn
/* PR target/17377
2
   Bug in code emitted by "return" pattern on CRIS: missing pop of
3
   forced return address on stack.  */
4
int calls = 0;
5
 
6
void *f (int) __attribute__ ((__noinline__));
7
void *
8
f (int i)
9
{
10
  /* The code does a little brittle song and dance to trig the "return"
11
     pattern instead of the function epilogue.  This must still be a
12
     leaf function for the bug to be exposed.  */
13
 
14
  if (calls++ == 0)
15
    return __builtin_return_address (0);
16
 
17
  switch (i)
18
    {
19
    case 1:
20
      return f;
21
    case 0:
22
      return __builtin_return_address (0);
23
    }
24
  return 0;
25
}
26
 
27
int x;
28
 
29
void *y (int i) __attribute__ ((__noinline__,__noclone__));
30
void *
31
y (int i)
32
{
33
  x = 0;
34
 
35
  /* This must not be a sibling call: the return address must appear
36
     constant for different calls to this function.  Postincrementing x
37
     catches otherwise unidentified multiple returns (e.g. through the
38
     return-address register and then this epilogue popping the address
39
     stored on stack in "f").  */
40
  return (char *) f (i) + x++;
41
}
42
 
43
int
44
main (void)
45
{
46
  void *v = y (4);
47
  if (y (1) != f
48
      /* Can't reasonably check the validity of the return address
49
         above, but it's not that important: the test-case will probably
50
         crash on the first call to f with the bug present, or it will
51
         run wild including returning early (in y or here), so we also
52
         try and check the number of calls.  */
53
      || y (0) != v
54
      || y (3) != 0
55
      || y (-1) != 0
56
      || calls != 5)
57
    abort ();
58
  exit (0);
59
}

powered by: WebSVN 2.1.0

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