cae6862c7a8542e9679abf05c59bcbc2f1c7d690
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / align.exp
1 # Copyright 2018-2019 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 C++ alignof works in gdb, and that it agrees with
19 # the compiler.
20
21 if {[skip_cplus_tests]} { continue }
22
23 # The types we're going to test.
24
25 set typelist {
26 char {unsigned char}
27 short {unsigned short}
28 int {unsigned int}
29 long {unsigned long}
30 {long long} {unsigned long long}
31 float
32 double {long double}
33 empty
34 bigenum
35 vstruct
36 bfstruct
37 arrstruct
38 derived
39 derived2
40 }
41
42 if {[has_int128_cxx]} {
43 # Note we don't check "unsigned __int128" yet because at least gcc
44 # canonicalizes the name to "__int128 unsigned", and there isn't a
45 # c-exp.y production for this.
46 # https://sourceware.org/bugzilla/show_bug.cgi?id=20991
47 lappend typelist __int128
48 }
49
50 # Create the test file.
51
52 set filename [standard_output_file align.cc]
53 set outfile [open $filename w]
54
55 # Prologue.
56 puts $outfile {
57 template<typename T, typename U>
58 struct align_pair
59 {
60 T one;
61 U two;
62 };
63
64 template<typename T, typename U>
65 struct align_union
66 {
67 T one;
68 U two;
69 };
70
71 enum bigenum { VALUE = 0xffffffffull };
72
73 struct empty { };
74
75 struct vstruct { virtual ~vstruct() {} char c; };
76
77 struct bfstruct { unsigned b : 3; };
78
79 struct arrstruct { short fld[7]; };
80
81 unsigned a_int3 = alignof (int[3]);
82
83 unsigned a_void = alignof (void);
84
85 struct base { char c; };
86 struct derived : public virtual base { int i; };
87
88 struct b2 : public virtual base { char d; };
89 struct derived2 : public b2, derived { char e; };
90 }
91
92 # First emit single items.
93 foreach type $typelist {
94 set utype [join [split $type] _]
95 puts $outfile "$type item_$utype;"
96 puts $outfile "unsigned a_$utype\n = alignof ($type);"
97 puts $outfile "typedef $type t_$utype;"
98 puts $outfile "t_$utype item_t_$utype;"
99 }
100
101 # Now emit all pairs.
102 foreach type $typelist {
103 set utype [join [split $type] _]
104 foreach inner $typelist {
105 set uinner [join [split $inner] _]
106 puts $outfile "align_pair<$type, $inner> item_${utype}_x_${uinner};"
107 puts $outfile "unsigned a_${utype}_x_${uinner}"
108 puts $outfile " = alignof (align_pair<$type, $inner>);"
109
110 puts $outfile "align_union<$type, $inner> item_${utype}_u_${uinner};"
111 puts $outfile "unsigned a_${utype}_u_${uinner}"
112 puts $outfile " = alignof (align_union<$type, $inner>);"
113 }
114 }
115
116 # Epilogue.
117 puts $outfile {
118 int main() {
119 return 0;
120 }
121 }
122
123 close $outfile
124
125 standard_testfile $filename
126
127 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
128 {debug nowarnings c++ additional_flags=-std=c++11}]} {
129 return -1
130 }
131
132 if {![runto_main]} {
133 perror "test suppressed"
134 return
135 }
136
137 proc maybe_xfail {type} {
138 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69560
139 # The g++ implementation of alignof is changing to match C11.
140 if {[is_x86_like_target]
141 && [test_compiler_info {gcc-[0-8]-*}]
142 && ($type == "double" || $type == "long long"
143 || $type == "unsigned long long")} {
144 setup_xfail *-*-*
145 }
146 }
147
148 foreach type $typelist {
149 set utype [join [split $type] _]
150 set expected [get_integer_valueof a_$utype 0]
151
152 maybe_xfail $type
153 gdb_test "print alignof($type)" " = $expected"
154
155 maybe_xfail $type
156 gdb_test "print alignof(t_$utype)" " = $expected"
157
158 maybe_xfail $type
159 gdb_test "print alignof(typeof(item_$utype))" " = $expected"
160
161 foreach inner $typelist {
162 set uinner [join [split $inner] _]
163 set expected [get_integer_valueof a_${utype}_x_${uinner} 0]
164 gdb_test "print alignof(align_pair<${type},${inner}>)" " = $expected"
165
166 set expected [get_integer_valueof a_${utype}_u_${uinner} 0]
167 gdb_test "print alignof(align_union<${type},${inner}>)" " = $expected"
168 }
169 }
170
171 set expected [get_integer_valueof a_int3 0]
172 gdb_test "print alignof(int\[3\])" " = $expected"
173 set expected [get_integer_valueof a_void 0]
174 gdb_test "print alignof(void)" " = $expected"
This page took 0.032139 seconds and 3 git commands to generate.