Fix crash when exiting TUI with gdb -tui
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / vla-datatypes.c
CommitLineData
5854b38a
SA
1/* This testcase is part of GDB, the GNU debugger.
2
b811d2c2 3 Copyright 2014-2020 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
21struct foo
22{
23 int a;
24};
25
26typedef struct bar
27{
28 int x;
29 struct foo y;
30} BAR;
31
32void
33vla_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];
2f33032a
KS
53 };
54 /* Define a typedef for a VLA structure. */
55 typedef struct vla_struct vla_struct_typedef;
56 vla_struct_typedef vla_struct_object;
012370f6
TT
57
58 struct inner_vla_struct
59 {
60 int something;
61 int vla_field[n];
62 int after;
63 } inner_vla_struct_object;
64
2f33032a
KS
65 /* Define a structure which uses a typedef for the VLA field
66 to make sure that GDB creates the proper type for this field,
67 preventing a possible assertion failure (see gdb/21356). */
68 struct vla_struct_typedef_struct_member
69 {
70 int something;
71 vla_struct_typedef vla_object;
72 } vla_struct_typedef_struct_member_object;
73
012370f6
TT
74 union vla_union
75 {
76 int vla_field[n];
77 } vla_union_object;
78
2f33032a
KS
79 /* Like vla_struct_typedef_struct_member but a union type. */
80 union vla_struct_typedef_union_member
81 {
82 int something;
83 vla_struct_typedef vla_object;
84 } vla_struct_typedef_union_member_object;
85
012370f6
TT
86 vla_struct_object.something = n;
87 inner_vla_struct_object.something = n;
88 inner_vla_struct_object.after = n;
2f33032a
KS
89 vla_struct_typedef_struct_member_object.something = n * 2;
90 vla_struct_typedef_struct_member_object.vla_object.something = n * 3;
91 vla_struct_typedef_union_member_object.vla_object.something = n + 1;
5854b38a
SA
92 for (i = 0; i < n; i++)
93 {
94 int_vla[i] = i*2;
95 unsigned_int_vla[i] = i*2;
96 double_vla[i] = i/2.0;
97 float_vla[i] = i/2.0f;
98 long_vla[i] = i*2;
99 unsigned_long_vla[i] = i*2;
100 char_vla[i] = 'A';
101 short_vla[i] = i*2;
102 unsigned_short_vla[i] = i*2;
103 unsigned_char_vla[i] = 'A';
104 foo_vla[i].a = i*2;
105 bar_vla[i].x = i*2;
106 bar_vla[i].y.a = i*2;
012370f6
TT
107 vla_struct_object.vla_field[i] = i*2;
108 vla_union_object.vla_field[i] = i*2;
109 inner_vla_struct_object.vla_field[i] = i*2;
2f33032a
KS
110 vla_struct_typedef_struct_member_object.vla_object.vla_field[i]
111 = i * 3;
112 vla_struct_typedef_union_member_object.vla_object.vla_field[i]
113 = i * 3 - 1;
5854b38a
SA
114 }
115
116 size_t int_size = sizeof(int_vla); /* vlas_filled */
117 size_t uint_size = sizeof(unsigned_int_vla);
118 size_t double_size = sizeof(double_vla);
119 size_t float_size = sizeof(float_vla);
120 size_t long_size = sizeof(long_vla);
121 size_t char_size = sizeof(char_vla);
122 size_t short_size = sizeof(short_vla);
123 size_t ushort_size = sizeof(unsigned_short_vla);
124 size_t uchar_size = sizeof(unsigned_char_vla);
125 size_t foo_size = sizeof(foo_vla);
126 size_t bar_size = sizeof(bar_vla);
012370f6
TT
127 size_t vla_struct_object_size = sizeof(vla_struct_object);
128 size_t vla_union_object_size = sizeof(vla_union_object);
6908c509 129 size_t inner_vla_struct_object_size = sizeof(inner_vla_struct_object);
5854b38a
SA
130
131 return; /* break_end_of_vla_factory */
132}
133
134int
135main (void)
136{
137 vla_factory(SIZE);
138 return 0;
139}
This page took 0.811596 seconds and 4 git commands to generate.