Skip to content

Commit b0f0ac3

Browse files
authored
Add overload of DIBuilder::createArrayType (llvm#125229)
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 45ca39d commit b0f0ac3

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

llvm/include/llvm/IR/DIBuilder.h

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

591+
/// Create debugging information entry for an array.
592+
/// \param Scope Scope in which this enumeration is defined.
593+
/// \param Name Union name.
594+
/// \param File File where this member is defined.
595+
/// \param LineNumber Line number.
596+
/// \param Size Array size.
597+
/// \param AlignInBits Alignment.
598+
/// \param Ty Element type.
599+
/// \param Subscripts Subscripts.
600+
/// \param DataLocation The location of the raw data of a descriptor-based
601+
/// Fortran array, either a DIExpression* or
602+
/// a DIVariable*.
603+
/// \param Associated The associated attribute of a descriptor-based
604+
/// Fortran array, either a DIExpression* or
605+
/// a DIVariable*.
606+
/// \param Allocated The allocated attribute of a descriptor-based
607+
/// Fortran array, either a DIExpression* or
608+
/// a DIVariable*.
609+
/// \param Rank The rank attribute of a descriptor-based
610+
/// Fortran array, either a DIExpression* or
611+
/// a DIVariable*.
612+
DICompositeType *createArrayType(
613+
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
614+
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
615+
PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
616+
PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
617+
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
618+
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
619+
591620
/// Create debugging information entry for a vector type.
592621
/// \param Size Array size.
593622
/// \param AlignInBits Alignment.

llvm/lib/IR/DIBuilder.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,21 @@ DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty,
601601
PointerUnion<DIExpression *, DIVariable *> AS,
602602
PointerUnion<DIExpression *, DIVariable *> AL,
603603
PointerUnion<DIExpression *, DIVariable *> RK) {
604+
return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits,
605+
Ty, Subscripts, DL, AS, AL, RK);
606+
}
607+
608+
DICompositeType *DIBuilder::createArrayType(
609+
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
610+
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
611+
PointerUnion<DIExpression *, DIVariable *> DL,
612+
PointerUnion<DIExpression *, DIVariable *> AS,
613+
PointerUnion<DIExpression *, DIVariable *> AL,
614+
PointerUnion<DIExpression *, DIVariable *> RK) {
604615
auto *R = DICompositeType::get(
605-
VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size,
606-
AlignInBits, 0, DINode::FlagZero, Subscripts, 0,
607-
/*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
616+
VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
617+
getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
618+
Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr,
608619
isa<DIExpression *>(DL) ? (Metadata *)cast<DIExpression *>(DL)
609620
: (Metadata *)cast<DIVariable *>(DL),
610621
isa<DIExpression *>(AS) ? (Metadata *)cast<DIExpression *>(AS)

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)