summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/20010122-1.c
blob: 280e3d45c9eb3cc64466c57e3b24d2ab5aa3f68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
extern void exit (int);
extern void abort (void);
extern void *alloca (__SIZE_TYPE__);
char *dummy (void);

#define NOINLINE __attribute__((noinline))

void *save_ret1[6];
void *test4a (char *);
void *test5a (char *);
void *test6a (char *);

void NOINLINE *test1 (void)
{
  void * temp;
  temp = __builtin_return_address (0);
  return temp;
}

void NOINLINE *test2 (void)
{
  void * temp;
  dummy ();
  temp = __builtin_return_address (0);
  return temp;
}

void NOINLINE *test3 (void)
{
  void * temp;
  temp = __builtin_return_address (0);
  dummy ();
  return temp;
}

void NOINLINE *test4 (void)
{
  char * save = (char*) alloca (4);
  
  return test4a (save);
}

void *NOINLINE test4a (char * p)
{
  void * temp;
  temp = __builtin_return_address (1);
  return temp;
}

void NOINLINE *test5 (void)
{
  char * save = (char*) alloca (4);
  
  return test5a (save);
}

void NOINLINE *test5a (char * p)
{
  void * temp;
  dummy ();
  temp = __builtin_return_address (1);
  return temp;
}

void NOINLINE *test6 (void)
{
  char * save = (char*) alloca (4);
  
  return test6a (save);
}

void NOINLINE *test6a (char * p)
{
  void * temp;
  temp = __builtin_return_address (1);
  dummy ();
  return temp;
}

void *(*func1[6])(void) = { test1, test2, test3, test4, test5, test6 };

char * NOINLINE call_func1 (int i)
{
  save_ret1[i] = func1[i] ();
}

static void *ret_addr;
void *save_ret2[6];
void test10a (char *);
void test11a (char *);
void test12a (char *);

void NOINLINE test7 (void)
{
  ret_addr = __builtin_return_address (0);
  return;
}

void NOINLINE test8 (void)
{
  dummy ();
  ret_addr = __builtin_return_address (0);
  return;
}

void NOINLINE test9 (void)
{
  ret_addr = __builtin_return_address (0);
  dummy ();
  return;
}

void NOINLINE test10 (void)
{
  char * save = (char*) alloca (4);
  
  test10a (save);
}

void NOINLINE test10a (char * p)
{
  ret_addr = __builtin_return_address (1);
  return;
}

void NOINLINE test11 (void)
{
  char * save = (char*) alloca (4);
  
  test11a (save);
}

void NOINLINE test11a (char * p)
{
  dummy ();
  ret_addr = __builtin_return_address (1);
  return;
}

void NOINLINE test12 (void)
{
  char * save = (char*) alloca (4);
  
  test12a (save);
}

void NOINLINE test12a (char * p)
{
  ret_addr = __builtin_return_address (1);
  dummy ();
  return;
}

char * dummy (void)
{
  char * save = (char*) alloca (4);
  
  return save;
}

void (*func2[6])(void) = { test7, test8, test9, test10, test11, test12 };

void NOINLINE call_func2 (int i)
{
  func2[i] ();
  save_ret2[i] = ret_addr;
}

int main (void)
{
  int i;

  for (i = 0; i < 6; i++) {
    call_func1(i);
  }

  if (save_ret1[0] != save_ret1[1]
      || save_ret1[1] != save_ret1[2])
    abort ();
  if (save_ret1[3] != save_ret1[4]
      || save_ret1[4] != save_ret1[5])
    abort ();
  if (save_ret1[3] && save_ret1[0] != save_ret1[3])
    abort ();


  for (i = 0; i < 6; i++) {
    call_func2(i);
  }

  if (save_ret2[0] != save_ret2[1]
      || save_ret2[1] != save_ret2[2])
    abort ();
  if (save_ret2[3] != save_ret2[4]
      || save_ret2[4] != save_ret2[5])
    abort ();
  if (save_ret2[3] && save_ret2[0] != save_ret2[3])
    abort ();

  exit (0);
}