Handle alignof and _Alignof
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / align.exp
1 # Copyright 2018 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 # This file is part of the gdb testsuite
17
18 # This tests that C11 _Alignof works in gdb, and that it agrees with
19 # the compiler.
20
21 # The types we're going to test.
22
23 set typelist {
24 char {unsigned char}
25 short {unsigned short}
26 int {unsigned int}
27 long {unsigned long}
28 {long long} {unsigned long long}
29 float
30 double {long double}
31 }
32
33 if {[has_int128_c]} {
34 # Note we don't check "unsigned __int128" yet because at least gcc
35 # canonicalizes the name to "__int128 unsigned", and there isn't a
36 # c-exp.y production for this.
37 # https://sourceware.org/bugzilla/show_bug.cgi?id=20991
38 lappend typelist __int128
39 }
40
41 # Create the test file.
42
43 set filename [standard_output_file align.c]
44 set outfile [open $filename w]
45
46 # Prologue.
47 puts -nonewline $outfile "#define DEF(T,U) struct align_pair_ ## T ## _x_ ## U "
48 puts $outfile "{ T one; U two; }"
49 puts $outfile "unsigned a_void = _Alignof(void);"
50
51 # First emit single items.
52 foreach type $typelist {
53 set utype [join [split $type] _]
54 if {$type != $utype} {
55 puts $outfile "typedef $type $utype;"
56 }
57 puts $outfile "$type item_$utype;"
58 puts $outfile "unsigned a_$utype\n = _Alignof ($type);"
59 set utype [join [split $type] _]
60 }
61
62 # Now emit all pairs.
63 foreach type $typelist {
64 set utype [join [split $type] _]
65 foreach inner $typelist {
66 set uinner [join [split $inner] _]
67 puts $outfile "DEF ($utype, $uinner);"
68 set joined "${utype}_x_${uinner}"
69 puts $outfile "struct align_pair_$joined item_${joined};"
70 puts $outfile "unsigned a_${joined}"
71 puts $outfile " = _Alignof (struct align_pair_${joined});"
72 }
73 }
74
75 # Epilogue.
76 puts $outfile {
77 int main() {
78 return 0;
79 }
80 }
81
82 close $outfile
83
84 standard_testfile $filename
85
86 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} {
87 return -1
88 }
89
90 if {![runto_main]} {
91 perror "test suppressed"
92 return
93 }
94
95 foreach type $typelist {
96 set utype [join [split $type] _]
97 set expected [get_integer_valueof a_$utype 0]
98 gdb_test "print _Alignof($type)" " = $expected"
99
100 foreach inner $typelist {
101 set uinner [join [split $inner] _]
102 set expected [get_integer_valueof a_${utype}_x_${uinner} 0]
103 gdb_test "print _Alignof(struct align_pair_${utype}_x_${uinner})" \
104 " = $expected"
105 }
106 }
107
108 set expected [get_integer_valueof a_void 0]
109 gdb_test "print _Alignof(void)" " = $expected"
This page took 0.031875 seconds and 4 git commands to generate.