On 11/17/24 9:01 AM, Mark Harmstone wrote:
If a CodeView struct, class, or union has as a member an anonymous
struct, class, or union, this gets flattened. The sub-struct's members
will appear as if they were part of their parent.

For this, we move part of get_type_num_struct into a new function
add_to_fieldlist, which also handles creating an LF_INDEX overflow item
if an LF_FIELDLIST grows too large. This is because add_struct_member
now calls itself recursively, and so needs to handle overflows itself.

gcc/
        * dwarf2codeview.cc (add_to_fieldlist): New function.
        (add_struct_member): Call recursively to flatten structs, and call
        add_to_fieldlist.
        (add_struct_static_member): Call add_to_fieldlist.
        (add_struct_function): Call add_to_fieldlist.
        (add_struct_inheritance): Call add_to_fieldlist.
        (add_struct_nested_type): Call add_to_fieldlist.
        (get_type_num_struct): Move code to add_to_fieldlist, and move
        responsibility for this to subfunctions.

@@ -5933,36 +5979,69 @@ create_bitfield (dw_die_ref c)
static void
  add_struct_member (dw_die_ref c, uint16_t accessibility,
-                  codeview_subtype **el, size_t *el_len)
+                  codeview_custom_type **ct, uint16_t *num_members,
+                  unsigned int base_offset)
  {
-  *el = (codeview_subtype *) xmalloc (sizeof (**el));
-  (*el)->next = NULL;
-  (*el)->kind = LF_MEMBER;
-  (*el)->lf_member.attributes = accessibility;
+  codeview_subtype *el;
+  size_t el_len;
+  dw_die_ref type = get_AT_ref (c, DW_AT_type);
+  unsigned int offset;
+
+  offset = base_offset + get_AT_unsigned (c, DW_AT_data_member_location);
+
+  /* If the data member is actually an anonymous struct, class, or union,
+     follow MSVC by flattening this into its parent.  */
+  if (!get_AT_string (c, DW_AT_name) && type
+      && (dw_get_die_tag (type) == DW_TAG_structure_type
+      || dw_get_die_tag (type) == DW_TAG_class_type
+      || dw_get_die_tag (type) == DW_TAG_union_type))
I suspect there's a formatting goof here. The || lines should be linking up under the first "dw_get_die_tag" call. It's possible this is just a mailer goof, but it's definitely worth checking.

OK with the formatting fix noted above. Or if no fix is needed, then OK as-is.

Thanks,
Jeff

Reply via email to