1 # Copyright 2018-2019 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite
18 # This tests that C++ alignof works in gdb, and that it agrees with
21 if {[skip_cplus_tests]} { continue }
23 # The types we're going to test.
27 short {unsigned short}
30 {long long} {unsigned long long}
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
50 # Create the test file.
52 set filename [standard_output_file align.cc]
53 set outfile [open $filename w]
57 template<typename T, typename U>
64 template<typename T, typename U>
71 enum bigenum { VALUE = 0xffffffffull };
75 struct vstruct { virtual ~vstruct() {} char c; };
77 struct bfstruct { unsigned b : 3; };
79 struct arrstruct { short fld[7]; };
81 unsigned a_int3 = alignof (int[3]);
83 unsigned a_void = alignof (void);
85 struct base { char c; };
86 struct derived : public virtual base { int i; };
88 struct b2 : public virtual base { char d; };
89 struct derived2 : public b2, derived { char e; };
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;"
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>);"
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>);"
125 standard_testfile $filename
127 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
128 {debug nowarnings c++ additional_flags=-std=c++11}]} {
133 perror "test suppressed"
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")} {
148 foreach type $typelist {
149 set utype [join [split $type] _]
150 set expected [get_integer_valueof a_$utype 0]
153 gdb_test "print alignof($type)" " = $expected"
156 gdb_test "print alignof(t_$utype)" " = $expected"
159 gdb_test "print alignof(typeof(item_$utype))" " = $expected"
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"
166 set expected [get_integer_valueof a_${utype}_u_${uinner} 0]
167 gdb_test "print alignof(align_union<${type},${inner}>)" " = $expected"
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"