[PATCH] D66352: Debug Info: Support for DW_AT_export_symbols for anonymous structs

Shafik Yaghmour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 21:11:45 PDT 2019


shafik added a comment.

In D66352#1636298 <https://reviews.llvm.org/D66352#1636298>, @dblaikie wrote:

> The difference between those two cases would be based on their usage - the types are the same (kinda, basically). In one case there's an anonymous member of the anonymous type (so it's transparent/all the nested names are as-if they were names of members in the outer type) and in the other case there's a named variable of the anonymous type (so the named members are members of that outer member variable).


The motivation for this change comes from assert that we were seeing during expression parsing when doing code completion see D66175 <https://reviews.llvm.org/D66175> for more details. Basically we were incorrectly marking lambda, unnamed struct and anonymous structs as anonymous. We put in an improved heuristic but this would allow us to correctly identify anonymous classes in all cases. In expression parsing we are handing off the AST to an embedded clang parser and the assumptions clang are making are valid assumptions if we got the AST correct.

One could argue we could parse the members of the containing class in order to figure out if the struct has a name. From the previous example I gave we would be looking for something like this:

  0x0000009c:     DW_TAG_member
                    DW_AT_name    ("C")
                    DW_AT_type    (0x00000000000000a8 "structure ")
                    DW_AT_decl_file       ("/Users/shafik/code/anon_class.cpp")
                    DW_AT_decl_line       (7)
                    DW_AT_data_member_location    (0x04)

but it gets more tricky if for example we have an array of the unnamed struct:

  struct A { 
  //...
     struct {
         int y;
     } C[10];
  };

the DWARF looks like this:

  0x0000009c:     DW_TAG_member
                    DW_AT_name    ("C")
                    DW_AT_type    (0x00000000000000bb "structure [10]")
                    DW_AT_decl_file       ("/Users/shafik/code/anon_class_b.cpp")
                    DW_AT_decl_line       (7)
                    DW_AT_data_member_location    (0x04)
  
  ....
  
  0x000000bb:   DW_TAG_array_type
                  DW_AT_type      (0x00000000000000a8 "structure ")
  
  0x000000c0:     DW_TAG_subrange_type
                    DW_AT_type    (0x00000000000000c7 "__ARRAY_SIZE_TYPE__")
                    DW_AT_count   (0x0a)

and we have to recurse to find the array data to find that it points to the unnamed struct. This seems like a lot of work when we have an attribute we can apply and it is in the spec and so we are simply supporting a simpler and easy to maintain solution.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66352/new/

https://reviews.llvm.org/D66352





More information about the llvm-commits mailing list