summaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2025-03-25 18:14:07 -0600
committerGitHub <noreply@github.com>2025-03-25 17:14:07 -0700
commitf89129af8adfda5d9071210b771787e36ae8cd96 (patch)
tree7f80c7db5c90b5da0f8a88d5d7b7fad510e99ba8 /llvm/lib/Bitcode/Reader
parent584b24cd6de5fd8bcfefa0b4a57ddbbf58c14af1 (diff)
Add bit stride to DICompositeType (#131680)
In Ada, an array can be packed and the elements can take less space than their natural object size. For example, for this type: type Packed_Array is array (4 .. 8) of Boolean; pragma pack (Packed_Array); ... each element of the array occupies a single bit, even though the "natural" size for a Boolean in memory is a byte. In DWARF, this is represented by putting a DW_AT_bit_stride onto the array type itself. This patch adds a bit stride to DICompositeType so that gnat-llvm can emit DWARF for these sorts of arrays.
Diffstat (limited to 'llvm/lib/Bitcode/Reader')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 12794d3346e3..e87e5bde63d8 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1618,7 +1618,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPOSITE_TYPE: {
- if (Record.size() < 16 || Record.size() > 25)
+ if (Record.size() < 16 || Record.size() > 26)
return error("Invalid record");
// If we have a UUID and this is not a forward declaration, lookup the
@@ -1651,6 +1651,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Metadata *Rank = nullptr;
Metadata *Annotations = nullptr;
Metadata *Specification = nullptr;
+ Metadata *BitStride = 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
@@ -1702,6 +1703,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Record.size() > 23) {
Specification = getMDOrNull(Record[23]);
}
+ if (Record.size() > 25)
+ BitStride = getMDOrNull(Record[25]);
}
if (Record.size() > 24 && Record[24] != dwarf::DW_APPLE_ENUM_KIND_invalid)
@@ -1714,17 +1717,17 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SizeInBits, AlignInBits, OffsetInBits, Specification,
NumExtraInhabitants, Flags, Elements, RuntimeLang, EnumKind,
VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
- Allocated, Rank, Annotations);
+ Allocated, Rank, Annotations, BitStride);
// Create a node if we didn't get a lazy ODR type.
if (!CT)
- CT = GET_OR_DISTINCT(DICompositeType,
- (Context, Tag, Name, File, Line, Scope, BaseType,
- SizeInBits, AlignInBits, OffsetInBits, Flags,
- Elements, RuntimeLang, EnumKind, VTableHolder,
- TemplateParams, Identifier, Discriminator,
- DataLocation, Associated, Allocated, Rank,
- Annotations, Specification, NumExtraInhabitants));
+ CT = GET_OR_DISTINCT(
+ DICompositeType,
+ (Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
+ AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, EnumKind,
+ VTableHolder, TemplateParams, Identifier, Discriminator,
+ DataLocation, Associated, Allocated, Rank, Annotations,
+ Specification, NumExtraInhabitants, BitStride));
if (!IsNotUsedInTypeRef && Identifier)
MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));