[PATCH] D42082: Add DWARF for discriminated unions

Tom Tromey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 11:45:53 PST 2018


tromey added a comment.

In https://reviews.llvm.org/D42082#978667, @probinson wrote:

> The DWARF spec says:  "If the variant part has a discriminant, the discriminant is represented by a separate debugging information entry which is a child of the variant part entry.  This entry has the form of a structure data member entry.  The variant part entry will have a DW_AT_descr attribute whose value is a reference to the member entry for the discriminant."
>
> I read this as saying the discriminant goes under the variant_part;  it seems slightly redundant to have it both as a child and with a reference, but that's what it says.  If you want you can bring it up on dwarf-discuss and see if anyone else thinks the discriminant ought to go outside the variant_part, but as it stands I think that would not be syntactically valid.


Yeah, I guess I misread that.  FWIW GCC generates this style as well.  From an Ada test case:

  <1><7c0>: Abbrev Number: 4 (DW_TAG_structure_type)
     <7c1>   DW_AT_name        : (indirect string, offset: 0xb26): pck__rec
     <7c5>   DW_AT_byte_size   : 13 byte block: 97 94 1 99 95 0 0 0 23 7 9 fc 1a 
     <7d3>   DW_AT_decl_file   : 2
     <7d4>   DW_AT_decl_line   : 15
     <7d5>   DW_AT_sibling     : <0x817>
  <2><7d9>: Abbrev Number: 5 (DW_TAG_member)
     <7da>   DW_AT_name        : (indirect string, offset: 0xaf8): discr
     <7de>   DW_AT_decl_file   : 2
     <7df>   DW_AT_decl_line   : 15
     <7e0>   DW_AT_type        : <0x7af>
     <7e4>   DW_AT_data_member_location: 0
  <2><7e5>: Abbrev Number: 6 (DW_TAG_variant_part)
     <7e6>   DW_AT_discr       : <0x7d9>

I think this approach actually makes more sense, because surely the discriminant is something whose placement cannot vary.

I'm thinking now `DW_TAG_Rust_enum` would be a better fit for what I need.  This approach would let me handle univariant enums consistently as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D42082





More information about the llvm-commits mailing list