Skip to content

Commit 54316a2

Browse files
committed
Add overload of DIBuilder::createArrayType
DICompositeType has an attribute representing the name of a type, but currently it isn't possible to set this for array types via the DIBuilder method. This patch adds a new overload of DIBuilder::createArrayType that allows "full" construction of an array type. This is useful for Ada, where arrays are a bit more first-class than C.
1 parent 1f2c36a commit 54316a2

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,35 @@ namespace llvm {
606606
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
607607
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
608608

609+
/// Create debugging information entry for an array.
610+
/// \param Scope Scope in which this enumeration is defined.
611+
/// \param Name Union name.
612+
/// \param File File where this member is defined.
613+
/// \param LineNumber Line number.
614+
/// \param Size Array size.
615+
/// \param AlignInBits Alignment.
616+
/// \param Ty Element type.
617+
/// \param Subscripts Subscripts.
618+
/// \param DataLocation The location of the raw data of a descriptor-based
619+
/// Fortran array, either a DIExpression* or
620+
/// a DIVariable*.
621+
/// \param Associated The associated attribute of a descriptor-based
622+
/// Fortran array, either a DIExpression* or
623+
/// a DIVariable*.
624+
/// \param Allocated The allocated attribute of a descriptor-based
625+
/// Fortran array, either a DIExpression* or
626+
/// a DIVariable*.
627+
/// \param Rank The rank attribute of a descriptor-based
628+
/// Fortran array, either a DIExpression* or
629+
/// a DIVariable*.
630+
DICompositeType *createArrayType(
631+
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
632+
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
633+
PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
634+
PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
635+
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
636+
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
637+
609638
/// Create debugging information entry for a vector type.
610639
/// \param Size Array size.
611640
/// \param AlignInBits Alignment.

llvm/lib/IR/DIBuilder.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,29 @@ DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty,
617617
return R;
618618
}
619619

620+
DICompositeType *DIBuilder::createArrayType(
621+
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
622+
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
623+
PointerUnion<DIExpression *, DIVariable *> DL,
624+
PointerUnion<DIExpression *, DIVariable *> AS,
625+
PointerUnion<DIExpression *, DIVariable *> AL,
626+
PointerUnion<DIExpression *, DIVariable *> RK) {
627+
auto *R = DICompositeType::get(
628+
VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
629+
getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
630+
Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
631+
isa<DIExpression *>(DL) ? (Metadata *)cast<DIExpression *>(DL)
632+
: (Metadata *)cast<DIVariable *>(DL),
633+
isa<DIExpression *>(AS) ? (Metadata *)cast<DIExpression *>(AS)
634+
: (Metadata *)cast<DIVariable *>(AS),
635+
isa<DIExpression *>(AL) ? (Metadata *)cast<DIExpression *>(AL)
636+
: (Metadata *)cast<DIVariable *>(AL),
637+
isa<DIExpression *>(RK) ? (Metadata *)cast<DIExpression *>(RK)
638+
: (Metadata *)cast<DIVariable *>(RK));
639+
trackIfUnresolved(R);
640+
return R;
641+
}
642+
620643
DICompositeType *DIBuilder::createVectorType(uint64_t Size,
621644
uint32_t AlignInBits, DIType *Ty,
622645
DINodeArray Subscripts) {

llvm/unittests/IR/DebugInfoTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,12 @@ TEST(DIBuilder, CompositeTypes) {
12701270
DICompositeType *Array = DIB.createArrayType(8, 8, nullptr, {});
12711271
EXPECT_EQ(Array->getTag(), dwarf::DW_TAG_array_type);
12721272

1273+
StringRef ArrayNameExp = "AnArray";
1274+
DICompositeType *NamedArray =
1275+
DIB.createArrayType(nullptr, ArrayNameExp, nullptr, 0, 8, 8, nullptr, {});
1276+
EXPECT_EQ(NamedArray->getTag(), dwarf::DW_TAG_array_type);
1277+
EXPECT_EQ(NamedArray->getName(), ArrayNameExp);
1278+
12731279
DICompositeType *Vector = DIB.createVectorType(8, 8, nullptr, {});
12741280
EXPECT_EQ(Vector->getTag(), dwarf::DW_TAG_array_type);
12751281

0 commit comments

Comments
 (0)