Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Add DWARF for discriminated unions #118

Merged

Conversation

tromey
Copy link

@tromey tromey commented Jun 7, 2018

[ Note to rust-llvm reviewers: this is a patch that landed upstream already,
as shown by the git-svn-id. It is a prerequisite of the fix for https://github.com/rust-lang/rust/issues/32920 ]

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 rust-lang/rust#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.

Patch by Tom Tromey!

Differential Revision: https://reviews.llvm.org/D42082

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324426 91177308-0d34-0410-b5e6-96231b3b80d8

n 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 rust-lang/rust#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.

Patch by Tom Tromey!

Differential Revision: https://reviews.llvm.org/D42082

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324426 91177308-0d34-0410-b5e6-96231b3b80d8
@alexcrichton alexcrichton merged commit 7a5f6ca into rust-lang:rust-llvm-release-6-0-0 Jun 27, 2018
@tromey tromey deleted the variant-part-backport branch June 27, 2018 16:55
bors added a commit to rust-lang/rust that referenced this pull request Jun 29, 2018
Update LLVM to 1c817c7a0c828b8fc8e8e462afbe5db41c7052d1

rust-lang/llvm#118
rust-lang/llvm#119
@matthieu-m
Copy link

@tromey Thank you for continuously working on improving the state of debugging Rust programs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants