gdb: Fix alignment computation for structs with only static fields

The current code in gdbtypes.c:type_align incorrectly returns 0 as the
alignment for a structure containing only static fields.  After this
patch the correct value of 1 is returned.  The gdb.base/align.exp test
is extended to cover this case.

gdb/ChangeLog:

	* gdbtypes.c (type_align): A struct with no non-static fields also
	has alignment of 1.

gdb/testsuite/ChangeLog:

	* gdb.base/align.exp: Extend test to cover structures containing
	only static fields.
This commit is contained in:
Andrew Burgess
2019-04-06 11:02:04 +01:00
parent 9f0272f854
commit 41077b6625
4 changed files with 34 additions and 12 deletions

View File

@@ -3014,16 +3014,12 @@ type_align (struct type *type)
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)
{
@@ -3035,6 +3031,10 @@ type_align (struct type *type)
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;