aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
authorAugusto Noronha <anoronha@apple.com>2024-11-13 09:55:37 -0800
committerGitHub <noreply@github.com>2024-11-13 09:55:37 -0800
commit67fb2686fba9abd6e607ff9a09b7018b2b8ae31b (patch)
tree9f2e90b07e93c45b480ac7d83022de740066966f /llvm/lib/Bitcode/Reader/MetadataLoader.cpp
parent2bd6af8cbc75ba67c20382757e03b85829d77a32 (diff)
downloadllvm-67fb2686fba9abd6e607ff9a09b7018b2b8ae31b.zip
llvm-67fb2686fba9abd6e607ff9a09b7018b2b8ae31b.tar.gz
llvm-67fb2686fba9abd6e607ff9a09b7018b2b8ae31b.tar.bz2
[DebugInfo] Add a specification attribute to LLVM DebugInfo (#115362)
Add a specification attribute to LLVM DebugInfo, which is analogous to DWARF's DW_AT_specification. According to the DWARF spec: "A debugging information entry that represents a declaration that completes another (earlier) non-defining declaration may have a DW_AT_specification attribute whose value is a reference to the debugging information entry representing the non-defining declaration." This patch allows types to be specifications of other types. This is used by Swift to represent generic types. For example, given this Swift program: ``` struct MyStruct<T> { let t: T } let variable = MyStruct<Int>(t: 43) ``` The Swift compiler emits (roughly) an unsubtituted type for MyStruct<T>: ``` DW_TAG_structure_type DW_AT_name ("MyStruct") // "$s1w8MyStructVyxGD" is a Swift mangled name roughly equivalent to // MyStruct<T> DW_AT_linkage_name ("$s1w8MyStructVyxGD") // other attributes here ``` And a specification for MyStruct<Int>: ``` DW_TAG_structure_type DW_AT_specification (<link to "MyStruct">) // "$s1w8MyStructVySiGD" is a Swift mangled name equivalent to // MyStruct<Int> DW_AT_linkage_name ("$s1w8MyStructVySiGD") DW_AT_byte_size (0x08) // other attributes here ```
Diffstat (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 8ca46a4..1caa848 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1600,7 +1600,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPOSITE_TYPE: {
- if (Record.size() < 16 || Record.size() > 23)
+ if (Record.size() < 16 || Record.size() > 24)
return error("Invalid record");
// If we have a UUID and this is not a forward declaration, lookup the
@@ -1630,6 +1630,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Metadata *Allocated = nullptr;
Metadata *Rank = nullptr;
Metadata *Annotations = nullptr;
+ Metadata *Specification = 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 as
@@ -1678,14 +1679,18 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Record.size() > 21) {
Annotations = getMDOrNull(Record[21]);
}
+ if (Record.size() > 23) {
+ Specification = getMDOrNull(Record[23]);
+ }
}
DICompositeType *CT = nullptr;
if (Identifier)
CT = DICompositeType::buildODRType(
Context, *Identifier, Tag, Name, File, Line, Scope, BaseType,
- SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants, Flags,
- Elements, RuntimeLang, VTableHolder, TemplateParams, Discriminator,
- DataLocation, Associated, Allocated, Rank, Annotations);
+ SizeInBits, AlignInBits, OffsetInBits, Specification,
+ NumExtraInhabitants, Flags, Elements, RuntimeLang, VTableHolder,
+ TemplateParams, Discriminator, DataLocation, Associated, Allocated,
+ Rank, Annotations);
// Create a node if we didn't get a lazy ODR type.
if (!CT)
@@ -1694,7 +1699,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SizeInBits, AlignInBits, OffsetInBits, Flags,
Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator, DataLocation, Associated,
- Allocated, Rank, Annotations, NumExtraInhabitants));
+ Allocated, Rank, Annotations, Specification,
+ NumExtraInhabitants));
if (!IsNotUsedInTypeRef && Identifier)
MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));