diff options
| author | Adrian Prantl <aprantl@apple.com> | 2018-02-06 23:45:59 +0000 |
|---|---|---|
| committer | Adrian Prantl <aprantl@apple.com> | 2018-02-06 23:45:59 +0000 |
| commit | 8c59921ca3284ced1c358c4c86ec2c830db0bd70 (patch) | |
| tree | 3147d5f8e22b4be9bea10fa0e9b295b19f4ca2a3 /llvm/lib/Bitcode | |
| parent | 4c687f38c6369de9ad2fe734b99abd743fa60026 (diff) | |
| download | bcm5719-llvm-8c59921ca3284ced1c358c4c86ec2c830db0bd70.tar.gz bcm5719-llvm-8c59921ca3284ced1c358c4c86ec2c830db0bd70.zip | |
Add DWARF for discriminated unions
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 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.
Patch by Tom Tromey!
Differential Revision: https://reviews.llvm.org/D42082
llvm-svn: 324426
Diffstat (limited to 'llvm/lib/Bitcode')
| -rw-r--r-- | llvm/lib/Bitcode/Reader/MetadataLoader.cpp | 7 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 1 |
2 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp index 5250ac5176d..c0ec80e9c01 100644 --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1246,7 +1246,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( break; } case bitc::METADATA_COMPOSITE_TYPE: { - if (Record.size() != 16) + if (Record.size() < 16 || Record.size() > 17) return error("Invalid record"); // If we have a UUID and this is not a forward declaration, lookup the @@ -1269,6 +1269,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( unsigned RuntimeLang = Record[12]; Metadata *VTableHolder = nullptr; Metadata *TemplateParams = nullptr; + Metadata *Discriminator = nullptr; auto *Identifier = getMDString(Record[15]); // If this module is being parsed so that it can be ThinLTO imported // into another module, composite types only need to be imported @@ -1289,13 +1290,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( Elements = getMDOrNull(Record[11]); VTableHolder = getDITypeRefOrNull(Record[13]); TemplateParams = getMDOrNull(Record[14]); + if (Record.size() > 16) + Discriminator = getMDOrNull(Record[16]); } DICompositeType *CT = nullptr; if (Identifier) CT = DICompositeType::buildODRType( Context, *Identifier, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, - VTableHolder, TemplateParams); + VTableHolder, TemplateParams, Discriminator); // Create a node if we didn't get a lazy ODR type. if (!CT) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 4cb38d7e254..76add4f7da3 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1526,6 +1526,7 @@ void ModuleBitcodeWriter::writeDICompositeType( Record.push_back(VE.getMetadataOrNullID(N->getVTableHolder())); Record.push_back(VE.getMetadataOrNullID(N->getTemplateParams().get())); Record.push_back(VE.getMetadataOrNullID(N->getRawIdentifier())); + Record.push_back(VE.getMetadataOrNullID(N->getDiscriminator())); Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE, Record, Abbrev); Record.clear(); |

