diff options
author | Tom Tromey <tromey@adacore.com> | 2025-02-24 11:11:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-24 10:11:53 -0800 |
commit | e298fc2da97120a30ee2f120ac184ab209fc1eb4 (patch) | |
tree | 3b72fa95d938b8ace37a479a1a119b73cd718dde /llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp | |
parent | 8dbc393e447299d1a4d35b96c6e66542a5928cff (diff) | |
download | llvm-e298fc2da97120a30ee2f120ac184ab209fc1eb4.zip llvm-e298fc2da97120a30ee2f120ac184ab209fc1eb4.tar.gz llvm-e298fc2da97120a30ee2f120ac184ab209fc1eb4.tar.bz2 |
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.
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp index de2263c..533c554 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp @@ -148,20 +148,21 @@ MCSymbol *DebugHandlerBase::getLabelAfterInsn(const MachineInstr *MI) { /// If this type is derived from a base type then return base type size. uint64_t DebugHandlerBase::getBaseTypeSize(const DIType *Ty) { assert(Ty); - const DIDerivedType *DDTy = dyn_cast<DIDerivedType>(Ty); - if (!DDTy) - return Ty->getSizeInBits(); - unsigned Tag = DDTy->getTag(); + unsigned Tag = Ty->getTag(); if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_atomic_type && Tag != dwarf::DW_TAG_immutable_type && Tag != dwarf::DW_TAG_template_alias) - return DDTy->getSizeInBits(); + return Ty->getSizeInBits(); - DIType *BaseType = DDTy->getBaseType(); + DIType *BaseType = nullptr; + if (const DIDerivedType *DDTy = dyn_cast<DIDerivedType>(Ty)) + BaseType = DDTy->getBaseType(); + else if (const DISubrangeType *SRTy = dyn_cast<DISubrangeType>(Ty)) + BaseType = SRTy->getBaseType(); if (!BaseType) return 0; @@ -187,6 +188,12 @@ bool DebugHandlerBase::isUnsignedDIType(const DIType *Ty) { return true; } + if (auto *SRTy = dyn_cast<DISubrangeType>(Ty)) { + Ty = SRTy->getBaseType(); + if (!Ty) + return false; + } + if (auto *CTy = dyn_cast<DICompositeType>(Ty)) { if (CTy->getTag() == dwarf::DW_TAG_enumeration_type) { if (!(Ty = CTy->getBaseType())) |