From e298fc2da97120a30ee2f120ac184ab209fc1eb4 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 24 Feb 2025 11:11:53 -0700 Subject: Add DISubrangeType (#126772) An Ada program can have types that are subranges of other types. This patch adds a new DIType node, DISubrangeType, to represent this concept. I considered extending the existing DISubrange to do this, but as DISubrange does not derive from DIType, that approach seemed more disruptive. A DISubrangeType can be used both as an ordinary type, but also as the type of an array index. This is also important for Ada. Ada subrange types can also be stored using a bias. Representing this in the DWARF required the use of an extension. GCC has been emitting this extension for years, so I've reused it here. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 450b8066540e..440a2c9ace8a 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -327,6 +327,8 @@ private: SmallVectorImpl &Record, unsigned Abbrev); void writeDIDerivedType(const DIDerivedType *N, SmallVectorImpl &Record, unsigned Abbrev); + void writeDISubrangeType(const DISubrangeType *N, + SmallVectorImpl &Record, unsigned Abbrev); void writeDICompositeType(const DICompositeType *N, SmallVectorImpl &Record, unsigned Abbrev); void writeDISubroutineType(const DISubroutineType *N, @@ -1937,6 +1939,27 @@ void ModuleBitcodeWriter::writeDIDerivedType(const DIDerivedType *N, Record.clear(); } +void ModuleBitcodeWriter::writeDISubrangeType(const DISubrangeType *N, + SmallVectorImpl &Record, + unsigned Abbrev) { + Record.push_back(N->isDistinct()); + Record.push_back(VE.getMetadataOrNullID(N->getRawName())); + Record.push_back(VE.getMetadataOrNullID(N->getFile())); + Record.push_back(N->getLine()); + Record.push_back(VE.getMetadataOrNullID(N->getScope())); + Record.push_back(N->getSizeInBits()); + Record.push_back(N->getAlignInBits()); + Record.push_back(N->getFlags()); + Record.push_back(VE.getMetadataOrNullID(N->getBaseType())); + Record.push_back(VE.getMetadataOrNullID(N->getRawLowerBound())); + Record.push_back(VE.getMetadataOrNullID(N->getRawUpperBound())); + Record.push_back(VE.getMetadataOrNullID(N->getRawStride())); + Record.push_back(VE.getMetadataOrNullID(N->getRawBias())); + + Stream.EmitRecord(bitc::METADATA_SUBRANGE_TYPE, Record, Abbrev); + Record.clear(); +} + void ModuleBitcodeWriter::writeDICompositeType( const DICompositeType *N, SmallVectorImpl &Record, unsigned Abbrev) { -- cgit v1.2.3