[PATCH] D42082: Add DWARF for discriminated unions

Tom Tromey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 11:00:48 PST 2018


tromey created this revision.
tromey added a reviewer: echristo.
Herald added subscribers: JDevlieghere, aprantl.

In Rust, an enum that carries data in the variants is, essentially, a
discriminated union.  Furthermore, the Rust compiler will perform
space optimizations on such enums in some situations.  Previously,
DWARF for these constructs was emitted using a hack (a magic field
name); but this approach stopped working when more space optimizations
were added in https://github.com/rust-lang/rust/pull/45225.

This patch changes LLVM to allow discriminated unions to be
represented in DWARF.  It adds createDiscriminatedUnionType and
createDiscriminatedMemberType to DIBuilder and then arranges for this
to be emitted using DWARF's DW_TAG_variant_part and DW_TAG_variant.

Note that DWARF requires that a discriminated union be represented as
a structure with a variant part.  However, as Rust only needs to emit
pure discriminated unions, this is what I chose to expose on
DIBuilder.


Repository:
  rL LLVM

https://reviews.llvm.org/D42082

Files:
  include/llvm/IR/DIBuilder.h
  include/llvm/IR/DebugInfoMetadata.h
  lib/AsmParser/LLParser.cpp
  lib/Bitcode/Reader/MetadataLoader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  lib/CodeGen/AsmPrinter/DwarfUnit.h
  lib/IR/AsmWriter.cpp
  lib/IR/DIBuilder.cpp
  lib/IR/DebugInfoMetadata.cpp
  test/DebugInfo/Generic/discriminated-union.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42082.129887.patch
Type: text/x-patch
Size: 28185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180115/3683abc3/attachment.bin>


More information about the llvm-commits mailing list