cvexpr.exp revision 1.5
1#   Copyright (C) 2001-2015 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Written by Michael Snyder, Red Hat, Inc., 9/20/2001
17
18# This file is part of the gdb testsuite
19# Tests for type expressions using const and volatile keywords.
20
21#
22# test running programs
23#
24
25standard_testfile .c
26
27if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
28     untested cvexpr.exp
29     return -1
30}
31
32clean_restart ${binfile}
33
34gdb_test_no_output "set print sevenbit-strings"
35gdb_test_no_output "set print address off"
36gdb_test_no_output "set width 0"
37
38set ws  "\[ \t\]*"
39
40#
41# Test casting a scalar to const
42#
43
44gdb_test "whatis (const char) v_char" \
45	"type = const char" \
46	"(const char)"
47gdb_test "whatis (const signed char) v_signed_char" \
48	"type = const signed char" \
49	"(const signed char)"
50gdb_test "whatis (const unsigned char) v_unsigned_char" \
51	"type = const (unsigned char|char)" \
52	"(const unsigned char)"
53gdb_test "whatis (const short) v_short" \
54	"type = const (short|short int)" \
55	"(const short)"
56gdb_test "whatis (const signed short) v_signed_short" \
57	"type = const (short|short int|signed short|signed short int)" \
58	"(const signed short)"
59gdb_test "whatis (const unsigned short) v_unsigned_short" \
60	"type = const (unsigned short|short unsigned int)" \
61	"(const unsigned short)"
62gdb_test "whatis (const int) v_int" \
63	"type = const int" \
64	"(const int)"
65gdb_test "whatis (const signed int) v_signed_int" \
66	"type = const (signed int|int)" \
67	"(const signed int)"
68gdb_test "whatis (const unsigned int) v_unsigned_int" \
69	"type = const unsigned int" \
70	"(const unsigned int)"
71gdb_test "whatis (const long) v_long" \
72	"type = const (long|long int)" \
73	"(const long)"
74gdb_test "whatis (const signed long) v_signed_long" \
75	"type = const (signed |)long( int|)" \
76	"(const signed long)"
77gdb_test "whatis (const unsigned long) v_unsigned_long" \
78	"type = const (unsigned long|long unsigned int)" \
79	"(const unsigned long)"
80gdb_test "whatis (const long long) v_long_long" \
81	"type = const long long( int|)" \
82	"(const long long)"
83gdb_test "whatis (const signed long long) v_signed_long_long" \
84	"type = const (signed |)long long( int|)" \
85	"(const signed long long)"
86gdb_test "whatis (const unsigned long long) v_unsigned_long_long" \
87	"type = const (unsigned long long|long long unsigned int)" \
88	"(const unsigned long long)"
89gdb_test "whatis (const float) v_float" \
90	"type = const float" \
91	"(const float)"
92gdb_test "whatis (const double) v_double" \
93	"type = const double" \
94	"(const double)"
95
96#
97# Test casting a scalar to volatile
98#
99
100gdb_test "whatis (volatile char) v_char" \
101	"type = volatile char" \
102	"(volatile char)"
103gdb_test "whatis (volatile signed char) v_signed_char" \
104	"type = volatile signed char" \
105	"(volatile signed char)"
106gdb_test "whatis (volatile unsigned char) v_unsigned_char" \
107	"type = volatile (unsigned char|char)" \
108	"(volatile unsigned char)"
109gdb_test "whatis (volatile short) v_short" \
110	"type = volatile (short|short int)" \
111	"(volatile short)"
112gdb_test "whatis (volatile signed short) v_signed_short" \
113	"type = volatile (short|short int|signed short|signed short int)" \
114	"(volatile signed short)"
115gdb_test "whatis (volatile unsigned short) v_unsigned_short" \
116	"type = volatile (unsigned short|short unsigned int)" \
117	"(volatile unsigned short)"
118gdb_test "whatis (volatile int) v_int" \
119	"type = volatile int" \
120	"(volatile int)"
121gdb_test "whatis (volatile signed int) v_signed_int" \
122	"type = volatile (signed int|int)" \
123	"(volatile signed int)"
124gdb_test "whatis (volatile unsigned int) v_unsigned_int" \
125	"type = volatile unsigned int" \
126	"(volatile unsigned int)"
127gdb_test "whatis (volatile long) v_long" \
128	"type = volatile (long|long int)" \
129	"(volatile long)"
130gdb_test "whatis (volatile signed long) v_signed_long" \
131	"type = volatile (signed |)long( int|)" \
132	"(volatile signed long)"
133gdb_test "whatis (volatile unsigned long) v_unsigned_long" \
134	"type = volatile (unsigned long|long unsigned int)" \
135	"(volatile unsigned long)"
136gdb_test "whatis (volatile long long) v_long_long" \
137	"type = volatile long long( int|)" \
138	"(volatile long long)"
139gdb_test "whatis (volatile signed long long) v_signed_long_long" \
140	"type = volatile (signed |)long long( int|)" \
141	"(volatile signed long long)"
142gdb_test "whatis (volatile unsigned long long) v_unsigned_long_long" \
143	"type = volatile (unsigned long long|long long unsigned int)" \
144	"(volatile unsigned long long)"
145gdb_test "whatis (volatile float) v_float" \
146	"type = volatile float" \
147	"(volatile float)"
148gdb_test "whatis (volatile double) v_double" \
149	"type = volatile double" \
150	"(volatile double)"
151
152#
153# Combine const and volatile
154#
155
156gdb_test "whatis (const volatile int) v_int" \
157	"type = const volatile int" \
158	"(const volatile int)"
159gdb_test "whatis (volatile const int) v_int" \
160	"type = const volatile int" \
161	"(volatile const int)"
162gdb_test "whatis (const int volatile) v_int" \
163	"type = const volatile int" \
164	"(const int volatile)"
165gdb_test "whatis (volatile int const) v_int" \
166	"type = const volatile int" \
167	"(volatile int const)"
168gdb_test "whatis (int const volatile) v_int" \
169	"type = const volatile int" \
170	"(int const volatile)"
171gdb_test "whatis (int volatile const) v_int" \
172	"type = const volatile int" \
173	"(int volatile const)"
174
175gdb_test "whatis (const volatile int *) v_int_pointer" \
176	"type = const volatile int${ws}\\*" \
177	"(const volatile int *)"
178gdb_test "whatis (volatile const int *) v_int_pointer" \
179	"type = const volatile int${ws}\\*" \
180	"(volatile const int *)"
181gdb_test "whatis (const int volatile *) v_int_pointer" \
182	"type = const volatile int${ws}\\*" \
183	"(const int volatile)"
184gdb_test "whatis (volatile int const *) v_int_pointer" \
185	"type = const volatile int${ws}\\*" \
186	"(volatile int const *)"
187gdb_test "whatis (int const volatile *) v_int_pointer" \
188	"type = const volatile int${ws}\\*" \
189	"(int const volatile *)"
190gdb_test "whatis (int volatile const *) v_int_pointer" \
191	"type = const volatile int${ws}\\*" \
192	"(int volatile const *)"
193gdb_test "whatis (int * const volatile) v_int_pointer" \
194	"type = int${ws}\\*${ws}const volatile" \
195	"(int * const volatile)"
196gdb_test "whatis (int * volatile const) v_int_pointer" \
197	"type = int${ws}\\*${ws}const volatile" \
198	"(int * volatile const)"
199
200
201#
202# Put 'signed' and 'unsigned' before const/volatile (FIXME)
203#
204
205#gdb_test "whatis (signed const char) v_signed_char" \
206#	"type = const char" \
207#	"(signed const char)"
208#gdb_test "whatis (unsigned const char) v_unsigned_char" \
209#	"type = const (unsigned char|char)" \
210#	"(unsigned const char)"
211#gdb_test "whatis (signed const short) v_signed_short" \
212#	"type = const (short|short int|signed short|signed short int)" \
213#	"(signed const short)"
214#gdb_test "whatis (unsigned const short) v_unsigned_short" \
215#	"type = const (unsigned short|short unsigned int)" \
216#	"(unsigned const short)"
217#gdb_test "whatis (signed const int) v_signed_int" \
218#	"type = const (signed int|int)" \
219#	"(signed const int)"
220#gdb_test "whatis (unsigned const int) v_unsigned_int" \
221#	"type = const unsigned int" \
222#	"(unsigned const int)"
223#gdb_test "whatis (signed const long) v_signed_long" \
224#	"type = const (signed |)long( int|)" \
225#	"(signed const long)"
226#gdb_test "whatis (unsigned const long) v_unsigned_long" \
227#	"type = const (unsigned long|long unsigned int)" \
228#	"(unsigned const long)"
229#gdb_test "whatis (signed const long long) v_signed_long_long" \
230#	"type = const (signed |)long long( int|)" \
231#	"(signed const long long)"
232#gdb_test "whatis (unsigned const long long) v_unsigned_long_long" \
233#	"type = const (unsigned long long|long long unsigned int)" \
234#	"(const unsigned long long)"
235
236#gdb_test "whatis (signed volatile char) v_signed_char" \
237#	"type = volatile char" \
238#	"(signed volatile char)"
239#gdb_test "whatis (unsigned volatile char) v_unsigned_char" \
240#	"type = volatile (unsigned char|char)" \
241#	"(unsigned volatile char)"
242#gdb_test "whatis (signed volatile short) v_signed_short" \
243#	"type = volatile (short|short int|signed short|signed short int)" \
244#	"(signed volatile short)"
245#gdb_test "whatis (unsigned volatile short) v_unsigned_short" \
246#	"type = volatile (unsigned short|short unsigned int)" \
247#	"(unsigned volatile short)"
248#gdb_test "whatis (signed volatile int) v_signed_int" \
249#	"type = volatile (signed int|int)" \
250#	"(signed volatile int)"
251#gdb_test "whatis (unsigned volatile int) v_unsigned_int" \
252#	"type = volatile unsigned int" \
253#	"(unsigned volatile int)"
254#gdb_test "whatis (signed volatile long) v_signed_long" \
255#	"type = volatile (signed |)long( int|)" \
256#	"(signed volatile long)"
257#gdb_test "whatis (unsigned volatile long) v_unsigned_long" \
258#	"type = volatile (unsigned long|long unsigned int)" \
259#	"(unsigned volatile long)"
260#gdb_test "whatis (signed volatile long long) v_signed_long_long" \
261#	"type = volatile (signed |)long long( int|)" \
262#	"(signed volatile long long)"
263#gdb_test "whatis (unsigned volatile long long) v_unsigned_long_long" \
264#	"type = volatile (unsigned long long|long long unsigned int)" \
265#	"(unsigned volatile long long)"
266
267#
268# Now put the 'const' and 'volatile' keywords after the base type.
269#
270
271gdb_test "whatis (char const) v_char" \
272	"type = const char" \
273	"(char const)"
274gdb_test "whatis (signed char const) v_signed_char" \
275	"type = const signed char" \
276	"(signed char const)"
277gdb_test "whatis (unsigned char const) v_unsigned_char" \
278	"type = const (unsigned char|char)" \
279	"(unsigned char const)"
280gdb_test "whatis (short const) v_short" \
281	"type = const (short|short int)" \
282	"(short const)"
283gdb_test "whatis (signed short const) v_signed_short" \
284	"type = const (short|short int|signed short|signed short int)" \
285	"(signed short const)"
286gdb_test "whatis (unsigned short const) v_unsigned_short" \
287	"type = const (unsigned short|short unsigned int)" \
288	"(unsigned short const)"
289gdb_test "whatis (int const) v_int" \
290	"type = const int" \
291	"(int const)"
292gdb_test "whatis (signed int const) v_signed_int" \
293	"type = const (signed int|int)" \
294	"(signed int const)"
295gdb_test "whatis (unsigned int const) v_unsigned_int" \
296	"type = const unsigned int" \
297	"(unsigned int const)"
298gdb_test "whatis (long const) v_long" \
299	"type = const (long|long int)" \
300	"(long const)"
301gdb_test "whatis (signed long const) v_signed_long" \
302	"type = const (signed |)long( int|)" \
303	"(signed long const)"
304gdb_test "whatis (unsigned long const) v_unsigned_long" \
305	"type = const (unsigned long|long unsigned int)" \
306	"(unsigned long const)"
307gdb_test "whatis (long long const) v_long_long" \
308	"type = const long long( int|)" \
309	"(long long const)"
310gdb_test "whatis (signed long long const) v_signed_long_long" \
311	"type = const (signed |)long long( int|)" \
312	"(signed long long const)"
313gdb_test "whatis (unsigned long long const) v_unsigned_long_long" \
314	"type = const (unsigned long long|long long unsigned int)" \
315	"(unsigned long long const)"
316gdb_test "whatis (float const) v_float" \
317	"type = const float" \
318	"(float const)"
319gdb_test "whatis (double const) v_double" \
320	"type = const double" \
321	"(double const)"
322
323gdb_test "whatis (char volatile) v_char" \
324	"type = volatile char" \
325	"(char volatile)"
326gdb_test "whatis (signed char volatile) v_signed_char" \
327	"type = volatile signed char" \
328	"(signed char volatile)"
329gdb_test "whatis (unsigned char volatile) v_unsigned_char" \
330	"type = volatile (unsigned char|char)" \
331	"(unsigned char volatile)"
332gdb_test "whatis (short volatile) v_short" \
333	"type = volatile (short|short int)" \
334	"(short volatile)"
335gdb_test "whatis (signed short volatile) v_signed_short" \
336	"type = volatile (short|short int|signed short|signed short int)" \
337	"(signed short volatile)"
338gdb_test "whatis (unsigned short volatile) v_unsigned_short" \
339	"type = volatile (unsigned short|short unsigned int)" \
340	"(unsigned short volatile)"
341gdb_test "whatis (int volatile) v_int" \
342	"type = volatile int" \
343	"(int volatile)"
344gdb_test "whatis (signed int volatile) v_signed_int" \
345	"type = volatile (signed int|int)" \
346	"(signed int volatile)"
347gdb_test "whatis (unsigned int volatile) v_unsigned_int" \
348	"type = volatile unsigned int" \
349	"(unsigned int volatile)"
350gdb_test "whatis (long volatile) v_long" \
351	"type = volatile (long|long int)" \
352	"(long volatile)"
353gdb_test "whatis (signed long volatile) v_signed_long" \
354	"type = volatile (signed |)long( int|)" \
355	"(signed long volatile)"
356gdb_test "whatis (unsigned long volatile) v_unsigned_long" \
357	"type = volatile (unsigned long|long unsigned int)" \
358	"(unsigned long volatile)"
359gdb_test "whatis (long long volatile) v_long_long" \
360	"type = volatile long long( int|)" \
361	"(long long volatile)"
362gdb_test "whatis (signed long long volatile) v_signed_long_long" \
363	"type = volatile (signed |)long long( int|)" \
364	"(signed long long volatile)"
365gdb_test "whatis (unsigned long long volatile) v_unsigned_long_long" \
366	"type = volatile (unsigned long long|long long unsigned int)" \
367	"(unsigned long long volatile)"
368gdb_test "whatis (float volatile) v_float" \
369	"type = volatile float" \
370	"(float volatile)"
371gdb_test "whatis (double volatile) v_double" \
372	"type = volatile double" \
373	"(double volatile)"
374
375#
376# enums
377#
378
379gdb_test "whatis (const enum misordered) v_misordered" \
380	"type = const enum misordered" \
381	"(const enum misordered)"
382gdb_test "whatis (enum misordered const) v_misordered" \
383	"type = const enum misordered" \
384	"(enum misordered const)"
385gdb_test "whatis (volatile enum misordered) v_misordered" \
386	"type = volatile enum misordered" \
387	"(volatile enum misordered)"
388gdb_test "whatis (enum misordered volatile) v_misordered" \
389	"type = volatile enum misordered" \
390	"(enum misordered volatile)"
391
392#
393# Pointers
394#
395
396gdb_test "whatis (const int *) v_int_pointer" \
397	"type = const int${ws}\\*" \
398	"(const int *)"
399gdb_test "whatis (int const *) v_int_pointer" \
400	"type = const int${ws}\\*" \
401	"(int const *)"
402gdb_test "whatis (int * const) v_int_pointer" \
403	"type = int \\*${ws}const" \
404	"(int * const)"
405gdb_test "whatis (const int * const) v_int_pointer" \
406	"type = const int${ws}\\*${ws}const" \
407	"(const int * const)"
408gdb_test "whatis (int const * const) v_int_pointer" \
409	"type = const int${ws}\\*${ws}const" \
410	"(int const * const)"
411
412gdb_test "whatis (const int **) v_int_pointer_pointer" \
413	"type = const int${ws}\\*${ws}\\*" \
414	"(const int **)"
415gdb_test "whatis (int const **) v_int_pointer_pointer" \
416	"type = const int${ws}\\*${ws}\\*" \
417	"(int const **)"
418gdb_test "whatis (int ** const) v_int_pointer_pointer" \
419	"type = int \\*${ws}\\*${ws}const" \
420	"(int ** const)"
421gdb_test "whatis (const int * const *) v_int_pointer_pointer" \
422	"type = const int${ws}\\*${ws}const${ws}\\*" \
423	"(const int * const *)"
424gdb_test "whatis (int const * const *) v_int_pointer_pointer" \
425	"type = const int${ws}\\*${ws}const${ws}\\*" \
426	"(int const * const *)"
427gdb_test "whatis (const int * const * const) v_int_pointer_pointer" \
428	"type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
429	"(const int * const * const)"
430gdb_test "whatis (int const * const * const) v_int_pointer_pointer" \
431	"type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
432	"(int const * const * const)"
433
434#
435# Arrays TODO
436#
437
438#
439# Pointers to arrays, arrays of pointers TODO
440#
441
442#
443# Structs and Unions
444#
445
446gdb_test "whatis (const struct t_struct) v_struct1" \
447	"type = const struct t_struct" \
448	"(const struct t_struct)"
449gdb_test "whatis (const union t_union) v_union" \
450	"type = const union t_union" \
451	"(const union t_union)"
452gdb_test "whatis (struct t_struct const) v_struct1" \
453	"type = const struct t_struct" \
454	"(struct t_struct const)"
455gdb_test "whatis (union t_union const) v_union" \
456	"type = const union t_union" \
457	"(union t_union const)"
458gdb_test "whatis (const struct t_struct *) &v_struct1" \
459	"type = const struct t_struct${ws}\\*" \
460	"(const struct t_struct *)"
461gdb_test "whatis (const union t_union *) &v_union" \
462	"type = const union t_union${ws}\\*" \
463	"(const union t_union *)"
464gdb_test "whatis (struct t_struct const *) &v_struct1" \
465	"type = const struct t_struct${ws}\\*" \
466	"(struct t_struct const *)"
467gdb_test "whatis (union t_union const *) &v_union" \
468	"type = const union t_union${ws}\\*" \
469	"(union t_union const *)"
470gdb_test "whatis (struct t_struct * const) &v_struct1" \
471	"type = struct t_struct${ws}\\*${ws}const" \
472	"(struct t_struct * const)"
473gdb_test "whatis (union t_union * const) &v_union" \
474	"type = union t_union${ws}\\*${ws}const" \
475	"(union t_union * const)"
476gdb_test "whatis (const struct t_struct * const) &v_struct1" \
477	"type = const struct t_struct${ws}\\*${ws}const" \
478	"(const struct t_struct * const)"
479gdb_test "whatis (const union t_union * const) &v_union" \
480	"type = const union t_union${ws}\\*${ws}const" \
481	"(const union t_union * const)"
482gdb_test "whatis (struct t_struct const * const) &v_struct1" \
483	"type = const struct t_struct${ws}\\*${ws}const" \
484	"(struct t_struct const * const)"
485gdb_test "whatis (union t_union const * const) &v_union" \
486	"type = const union t_union${ws}\\*${ws}const" \
487	"(union t_union const * const)"
488
489#
490# Function pointers TODO
491#
492
493