1 /* { dg-require-effective-target return_address } */
2 int check_fa_work (const char *, const char *) __attribute__((noinline));
3 int check_fa_mid (const char *) __attribute__((noinline));
4 int check_fa (char *) __attribute__((noinline));
5 int how_much (void) __attribute__((noinline));
6 
check_fa_work(const char * c,const char * f)7 int check_fa_work (const char *c, const char *f)
8 {
9   const char d = 0;
10 
11   if (c >= &d)
12     return c >= f && f >= &d;
13   else
14     return c <= f && f <= &d;
15 }
16 
check_fa_mid(const char * c)17 int check_fa_mid (const char *c)
18 {
19   const char *f = __builtin_frame_address (0);
20 
21   /* Prevent a tail call to check_fa_work, eliding the current stack frame.  */
22   return check_fa_work (c, f) != 0;
23 }
24 
check_fa(char * unused)25 int check_fa (char *unused)
26 {
27   const char c = 0;
28 
29   /* Prevent a tail call to check_fa_mid, eliding the current stack frame.  */
30   return check_fa_mid (&c) != 0;
31 }
32 
how_much(void)33 int how_much (void)
34 {
35 	return 8;
36 }
37 
main(void)38 int main (void)
39 {
40   char *unused = __builtin_alloca (how_much ());
41 
42   if (!check_fa(unused))
43     abort();
44   return 0;
45 }
46