1 # Copyright 2018-2020 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 # The types we're going to test.
22 short
{unsigned short
}
25 {long long
} {unsigned long long
}
31 # Note we don't check "unsigned __int128" yet because at least gcc
32 # canonicalizes the name to "__int128 unsigned", and there isn't a
33 # c-exp.y production for this.
34 # https://sourceware.org/bugzilla/show_bug.cgi?id=20991
35 lappend typelist __int128
38 # Build source file for testing alignment handling of language LANG.
39 # Returns the name of the newly created source file.
40 proc prepare_test_source_file
{ lang
} {
43 # Create the test file.
45 if { $lang == "c++" } {
47 set align_func
"alignof"
50 set align_func
"_Alignof"
53 set filename [standard_output_file
"align.$suffix"]
54 set outfile
[open $filename w
]
57 puts -nonewline $outfile "#define DEF(T,U) struct align_pair_ ## T ## _x_ ## U "
58 puts $outfile "{ T one; U two; }"
59 if { $lang == "c++" } {
60 puts -nonewline $outfile "#define DEF_WITH_1_STATIC(T,U) struct align_pair_static_ ## T ## _x_ ## U "
61 puts $outfile "{ static T one; U two; }"
62 puts -nonewline $outfile "#define DEF_WITH_2_STATIC(T,U) struct align_pair_static_ ## T ## _x_static_ ## U "
63 puts $outfile "{ static T one; static U two; }"
66 puts $outfile "unsigned a_void = ${align_func} (void);"
69 # First emit single items.
70 foreach type
$typelist {
71 set utype
[join [split $type] _
]
72 if {$type != $utype} {
73 puts $outfile "typedef $type $utype;"
75 puts $outfile "$type item_$utype;"
77 puts $outfile "unsigned a_$utype\n = ${align_func} ($type);"
79 set utype
[join [split $type] _
]
83 foreach type
$typelist {
84 set utype
[join [split $type] _
]
85 foreach inner
$typelist {
86 set uinner
[join [split $inner] _
]
87 puts $outfile "DEF ($utype, $uinner);"
88 set joined
"${utype}_x_${uinner}"
89 puts $outfile "struct align_pair_$joined item_${joined};"
90 puts $outfile "unsigned a_${joined}"
91 puts $outfile " = ${align_func} (struct align_pair_${joined});"
93 if { $lang == "c++" } {
94 puts $outfile "DEF_WITH_1_STATIC ($utype, $uinner);"
95 set joined
"static_${utype}_x_${uinner}"
96 puts $outfile "struct align_pair_$joined item_${joined};"
97 puts $outfile "unsigned a_${joined}"
98 puts $outfile " = ${align_func} (struct align_pair_${joined});"
100 puts $outfile "DEF_WITH_2_STATIC ($utype, $uinner);"
101 set joined
"static_${utype}_x_static_${uinner}"
102 puts $outfile "struct align_pair_$joined item_${joined};"
103 puts $outfile "unsigned a_${joined}"
104 puts $outfile " = ${align_func} (struct align_pair_${joined});"
121 # Run the alignment test for the language LANG.
122 proc run_alignment_test
{ lang
} {
123 global testfile srcfile typelist
126 set filename [prepare_test_source_file
$lang]
129 if { "$lang" == "c++" } {
130 lappend flags
"additional_flags=-std=c++11"
132 standard_testfile
$filename
133 if {[prepare_for_testing
"failed to prepare" "$testfile" $srcfile $flags]} {
138 perror
"test suppressed"
142 if { $lang == "c++" } {
143 set align_func
"alignof"
145 set align_func
"_Alignof"
148 foreach type
$typelist {
149 set utype
[join [split $type] _
]
150 if { $lang == "c" } {
151 set expected
[get_integer_valueof a_
$utype 0]
152 gdb_test
"print ${align_func}($type)" " = $expected"
155 foreach inner
$typelist {
156 set uinner
[join [split $inner] _
]
157 set expected
[get_integer_valueof a_
${utype
}_x_
${uinner
} 0]
158 gdb_test
"print ${align_func}(struct align_pair_${utype}_x_${uinner})" \
161 if { $lang == "c++" } {
162 set expected
[get_integer_valueof a_static_
${utype
}_x_
${uinner
} 0]
163 gdb_test
"print ${align_func}(struct align_pair_static_${utype}_x_${uinner})" \
166 set expected
[get_integer_valueof a_static_
${utype
}_x_static_
${uinner
} 0]
167 gdb_test
"print ${align_func}(struct align_pair_static_${utype}_x_static_${uinner})" \
173 if { $lang == "c" } {
174 set expected
[get_integer_valueof a_void
0]
175 gdb_test
"print ${align_func}(void)" " = $expected"
179 run_alignment_test
$lang