]>
Commit | Line | Data |
---|---|---|
5854b38a SA |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
42a4f53d | 3 | Copyright 2014-2019 Free Software Foundation, Inc. |
5854b38a SA |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include <stddef.h> | |
19 | #define SIZE 5 | |
20 | ||
21 | struct foo | |
22 | { | |
23 | int a; | |
24 | }; | |
25 | ||
26 | typedef struct bar | |
27 | { | |
28 | int x; | |
29 | struct foo y; | |
30 | } BAR; | |
31 | ||
32 | void | |
33 | vla_factory (int n) | |
34 | { | |
35 | int int_vla[n]; | |
36 | unsigned int unsigned_int_vla[n]; | |
37 | double double_vla[n]; | |
38 | float float_vla[n]; | |
39 | long long_vla[n]; | |
40 | unsigned long unsigned_long_vla[n]; | |
41 | char char_vla[n]; | |
42 | short short_vla[n]; | |
43 | unsigned short unsigned_short_vla[n]; | |
44 | unsigned char unsigned_char_vla[n]; | |
45 | struct foo foo_vla[n]; | |
46 | BAR bar_vla[n]; | |
47 | int i; | |
48 | ||
012370f6 TT |
49 | struct vla_struct |
50 | { | |
51 | int something; | |
52 | int vla_field[n]; | |
53 | } vla_struct_object; | |
54 | ||
55 | struct inner_vla_struct | |
56 | { | |
57 | int something; | |
58 | int vla_field[n]; | |
59 | int after; | |
60 | } inner_vla_struct_object; | |
61 | ||
62 | union vla_union | |
63 | { | |
64 | int vla_field[n]; | |
65 | } vla_union_object; | |
66 | ||
67 | vla_struct_object.something = n; | |
68 | inner_vla_struct_object.something = n; | |
69 | inner_vla_struct_object.after = n; | |
5854b38a SA |
70 | for (i = 0; i < n; i++) |
71 | { | |
72 | int_vla[i] = i*2; | |
73 | unsigned_int_vla[i] = i*2; | |
74 | double_vla[i] = i/2.0; | |
75 | float_vla[i] = i/2.0f; | |
76 | long_vla[i] = i*2; | |
77 | unsigned_long_vla[i] = i*2; | |
78 | char_vla[i] = 'A'; | |
79 | short_vla[i] = i*2; | |
80 | unsigned_short_vla[i] = i*2; | |
81 | unsigned_char_vla[i] = 'A'; | |
82 | foo_vla[i].a = i*2; | |
83 | bar_vla[i].x = i*2; | |
84 | bar_vla[i].y.a = i*2; | |
012370f6 TT |
85 | vla_struct_object.vla_field[i] = i*2; |
86 | vla_union_object.vla_field[i] = i*2; | |
87 | inner_vla_struct_object.vla_field[i] = i*2; | |
5854b38a SA |
88 | } |
89 | ||
90 | size_t int_size = sizeof(int_vla); /* vlas_filled */ | |
91 | size_t uint_size = sizeof(unsigned_int_vla); | |
92 | size_t double_size = sizeof(double_vla); | |
93 | size_t float_size = sizeof(float_vla); | |
94 | size_t long_size = sizeof(long_vla); | |
95 | size_t char_size = sizeof(char_vla); | |
96 | size_t short_size = sizeof(short_vla); | |
97 | size_t ushort_size = sizeof(unsigned_short_vla); | |
98 | size_t uchar_size = sizeof(unsigned_char_vla); | |
99 | size_t foo_size = sizeof(foo_vla); | |
100 | size_t bar_size = sizeof(bar_vla); | |
012370f6 TT |
101 | size_t vla_struct_object_size = sizeof(vla_struct_object); |
102 | size_t vla_union_object_size = sizeof(vla_union_object); | |
6908c509 | 103 | size_t inner_vla_struct_object_size = sizeof(inner_vla_struct_object); |
5854b38a SA |
104 | |
105 | return; /* break_end_of_vla_factory */ | |
106 | } | |
107 | ||
108 | int | |
109 | main (void) | |
110 | { | |
111 | vla_factory(SIZE); | |
112 | return 0; | |
113 | } |