case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
{
- if (TYPE_NFIELDS (type) == 0)
- {
- /* An empty struct has alignment 1. */
- align = 1;
- break;
- }
+ int number_of_non_static_fields = 0;
for (unsigned i = 0; i < TYPE_NFIELDS (type); ++i)
{
if (!field_is_static (&TYPE_FIELD (type, i)))
{
+ number_of_non_static_fields++;
ULONGEST f_align = type_align (TYPE_FIELD_TYPE (type, i));
if (f_align == 0)
{
align = f_align;
}
}
+ /* A struct with no fields, or with only static fields has an
+ alignment of 1. */
+ if (number_of_non_static_fields == 0)
+ align = 1;
}
break;
puts -nonewline $outfile "#define DEF(T,U) struct align_pair_ ## T ## _x_ ## U "
puts $outfile "{ T one; U two; }"
if { $lang == "c++" } {
- puts -nonewline $outfile "#define DEF_WITH_STATIC(T,U) struct align_pair_static_ ## T ## _x_ ## U "
+ puts -nonewline $outfile "#define DEF_WITH_1_STATIC(T,U) struct align_pair_static_ ## T ## _x_ ## U "
puts $outfile "{ static T one; U two; }"
+ puts -nonewline $outfile "#define DEF_WITH_2_STATIC(T,U) struct align_pair_static_ ## T ## _x_static_ ## U "
+ puts $outfile "{ static T one; static U two; }"
}
if { $lang == "c" } {
puts $outfile "unsigned a_void = ${align_func} (void);"
puts $outfile " = ${align_func} (struct align_pair_${joined});"
if { $lang == "c++" } {
- puts $outfile "DEF_WITH_STATIC ($utype, $uinner);"
- set joined "${utype}_x_${uinner}"
- puts $outfile "struct align_pair_static_$joined item_static_${joined};"
- puts $outfile "unsigned a_static_${joined}"
- puts $outfile " = ${align_func} (struct align_pair_static_${joined});"
+ puts $outfile "DEF_WITH_1_STATIC ($utype, $uinner);"
+ set joined "static_${utype}_x_${uinner}"
+ puts $outfile "struct align_pair_$joined item_${joined};"
+ puts $outfile "unsigned a_${joined}"
+ puts $outfile " = ${align_func} (struct align_pair_${joined});"
+
+ puts $outfile "DEF_WITH_2_STATIC ($utype, $uinner);"
+ set joined "static_${utype}_x_static_${uinner}"
+ puts $outfile "struct align_pair_$joined item_${joined};"
+ puts $outfile "unsigned a_${joined}"
+ puts $outfile " = ${align_func} (struct align_pair_${joined});"
}
}
}
set expected [get_integer_valueof a_static_${utype}_x_${uinner} 0]
gdb_test "print ${align_func}(struct align_pair_static_${utype}_x_${uinner})" \
" = $expected"
+
+ set expected [get_integer_valueof a_static_${utype}_x_static_${uinner} 0]
+ gdb_test "print ${align_func}(struct align_pair_static_${utype}_x_static_${uinner})" \
+ " = $expected"
}
}
}