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/IR/Verifier.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/IR/Verifier.cpp')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 310a673..b4f9273 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1154,6 +1154,30 @@ void Verifier::visitDIScope(const DIScope &N) { CheckDI(isa<DIFile>(F), "invalid file", &N, F); } +void Verifier::visitDISubrangeType(const DISubrangeType &N) { + CheckDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N); + auto *BaseType = N.getRawBaseType(); + CheckDI(!BaseType || isType(BaseType), "BaseType must be a type"); + auto *LBound = N.getRawLowerBound(); + CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) || + isa<DIVariable>(LBound) || isa<DIExpression>(LBound), + "LowerBound must be signed constant or DIVariable or DIExpression", + &N); + auto *UBound = N.getRawUpperBound(); + CheckDI(!UBound || isa<ConstantAsMetadata>(UBound) || + isa<DIVariable>(UBound) || isa<DIExpression>(UBound), + "UpperBound must be signed constant or DIVariable or DIExpression", + &N); + auto *Stride = N.getRawStride(); + CheckDI(!Stride || isa<ConstantAsMetadata>(Stride) || + isa<DIVariable>(Stride) || isa<DIExpression>(Stride), + "Stride must be signed constant or DIVariable or DIExpression", &N); + auto *Bias = N.getRawBias(); + CheckDI(!Bias || isa<ConstantAsMetadata>(Bias) || isa<DIVariable>(Bias) || + isa<DIExpression>(Bias), + "Bias must be signed constant or DIVariable or DIExpression", &N); +} + void Verifier::visitDISubrange(const DISubrange &N) { CheckDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N); CheckDI(!N.getRawCountNode() || !N.getRawUpperBound(), |