@@ -2036,8 +2036,10 @@ resolve_dynamic_union (struct type *type,
t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
addr_stack, 0);
TYPE_FIELD_TYPE (resolved_type, i) = t;
- if (TYPE_LENGTH (t) > max_len)
- max_len = TYPE_LENGTH (t);
+
+ struct type *real_type = check_typedef (t);
+ if (TYPE_LENGTH (real_type) > max_len)
+ max_len = TYPE_LENGTH (real_type);
}
TYPE_LENGTH (resolved_type) = max_len;
@@ -2103,8 +2105,12 @@ resolve_dynamic_struct (struct type *type,
if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
else
- new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
- * TARGET_CHAR_BIT);
+ {
+ struct type *real_type
+ = check_typedef (TYPE_FIELD_TYPE (resolved_type, i));
+
+ new_bit_length += (TYPE_LENGTH (real_type) * TARGET_CHAR_BIT);
+ }
/* Normally, we would use the position and size of the last field
to determine the size of the enclosing structure. But GCC seems
@@ -46,11 +46,14 @@ vla_factory (int n)
BAR bar_vla[n];
int i;
- struct vla_struct
+ /* Define a typedef for a VLA structure. */
+ typedef struct vla_struct
{
int something;
int vla_field[n];
- } vla_struct_object;
+ } vla_struct_t;
+
+ vla_struct_t vla_struct_object;
struct inner_vla_struct
{
@@ -59,14 +62,33 @@ vla_factory (int n)
int after;
} inner_vla_struct_object;
+ /* Define a structure which uses a typedef for the VLA field
+ to make sure that GDB creates the proper type for this field,
+ preventing a possible assertion failure (see gdb/21356). */
+ struct vla_struct_with_vla_typedef
+ {
+ int something;
+ vla_struct_t vla_object;
+ } vla_struct_with_vla_typedef_object;
+
union vla_union
{
int vla_field[n];
} vla_union_object;
+ /* Like vla_struct_with_vla_typedef but a union type. */
+ union vla_union_with_vla_typedef
+ {
+ int something;
+ vla_struct_t vla_object;
+ } vla_union_with_vla_typedef_object;
+
vla_struct_object.something = n;
inner_vla_struct_object.something = n;
inner_vla_struct_object.after = n;
+ vla_struct_with_vla_typedef_object.something = n * 2;
+ vla_struct_with_vla_typedef_object.vla_object.something = n * 3;
+ vla_union_with_vla_typedef_object.vla_object.something = n * 3 + 1;
for (i = 0; i < n; i++)
{
int_vla[i] = i*2;
@@ -85,6 +107,8 @@ vla_factory (int n)
vla_struct_object.vla_field[i] = i*2;
vla_union_object.vla_field[i] = i*2;
inner_vla_struct_object.vla_field[i] = i*2;
+ vla_struct_with_vla_typedef_object.vla_object.vla_field[i] = i * 3;
+ vla_union_with_vla_typedef_object.vla_object.vla_field[i] = i * 3 - 1;
}
size_t int_size = sizeof(int_vla); /* vlas_filled */
@@ -57,6 +57,10 @@ gdb_test "print vla_struct_object" \
"\\\{something = 5, vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
gdb_test "print vla_union_object" \
"\\\{vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
+gdb_test "print vla_struct_with_vla_typedef_object" \
+ "\\\{something = 10, vla_object = \\\{something = 15, vla_field = \\\{0, 3, 6, 9, 12\\\}\\\}\\\}"
+gdb_test "print vla_union_with_vla_typedef_object" \
+ "\\\{something = 16, vla_object = \\\{something = 16, vla_field = \\\{-1, 2, 5, 8, 11\\\}\\\}\\\}"
# Check whatis of VLA's.
gdb_test "whatis int_vla" "type = int \\\[5\\\]" "whatis int_vla"
@@ -78,7 +82,7 @@ gdb_test "whatis unsigned_char_vla" "type = unsigned char \\\[5\\\]" \
"whatis unsigned_char_vla"
gdb_test "whatis foo_vla" "type = struct foo \\\[5\\\]" "whatis foo_vla"
gdb_test "whatis bar_vla" "type = BAR \\\[5\\\]" "whatis bar_vla"
-gdb_test "whatis vla_struct_object" "type = struct vla_struct"
+gdb_test "whatis vla_struct_object" "type = vla_struct_t"
gdb_test "whatis vla_union_object" "type = union vla_union"
# Check ptype of VLA's.