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