diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h index f6520fd855988..4a6d563fcf7b4 100644 --- a/llvm/include/llvm/IR/DIBuilder.h +++ b/llvm/include/llvm/IR/DIBuilder.h @@ -588,6 +588,35 @@ namespace llvm { PointerUnion Allocated = nullptr, PointerUnion Rank = nullptr); + /// Create debugging information entry for an array. + /// \param Scope Scope in which this enumeration is defined. + /// \param Name Union name. + /// \param File File where this member is defined. + /// \param LineNumber Line number. + /// \param Size Array size. + /// \param AlignInBits Alignment. + /// \param Ty Element type. + /// \param Subscripts Subscripts. + /// \param DataLocation The location of the raw data of a descriptor-based + /// Fortran array, either a DIExpression* or + /// a DIVariable*. + /// \param Associated The associated attribute of a descriptor-based + /// Fortran array, either a DIExpression* or + /// a DIVariable*. + /// \param Allocated The allocated attribute of a descriptor-based + /// Fortran array, either a DIExpression* or + /// a DIVariable*. + /// \param Rank The rank attribute of a descriptor-based + /// Fortran array, either a DIExpression* or + /// a DIVariable*. + DICompositeType *createArrayType( + DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, + uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts, + PointerUnion DataLocation = nullptr, + PointerUnion Associated = nullptr, + PointerUnion Allocated = nullptr, + PointerUnion Rank = nullptr); + /// Create debugging information entry for a vector type. /// \param Size Array size. /// \param AlignInBits Alignment. diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index bbe4d1f56c23d..5ed2993387bc5 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -601,10 +601,21 @@ DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, PointerUnion AS, PointerUnion AL, PointerUnion RK) { + return createArrayType(nullptr, StringRef(), nullptr, 0, Size, AlignInBits, + Ty, Subscripts, DL, AS, AL, RK); +} + +DICompositeType *DIBuilder::createArrayType( + DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, + uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts, + PointerUnion DL, + PointerUnion AS, + PointerUnion AL, + PointerUnion RK) { auto *R = DICompositeType::get( - VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size, - AlignInBits, 0, DINode::FlagZero, Subscripts, 0, - /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr, + VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber, + getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero, + Subscripts, 0, /*EnumKind=*/std::nullopt, nullptr, nullptr, "", nullptr, isa(DL) ? (Metadata *)cast(DL) : (Metadata *)cast(DL), isa(AS) ? (Metadata *)cast(AS) diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp index 4283ba7a8f823..c632bd6d3cbb5 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -1270,6 +1270,12 @@ TEST(DIBuilder, CompositeTypes) { DICompositeType *Array = DIB.createArrayType(8, 8, nullptr, {}); EXPECT_EQ(Array->getTag(), dwarf::DW_TAG_array_type); + StringRef ArrayNameExp = "AnArray"; + DICompositeType *NamedArray = + DIB.createArrayType(nullptr, ArrayNameExp, nullptr, 0, 8, 8, nullptr, {}); + EXPECT_EQ(NamedArray->getTag(), dwarf::DW_TAG_array_type); + EXPECT_EQ(NamedArray->getName(), ArrayNameExp); + DICompositeType *Vector = DIB.createVectorType(8, 8, nullptr, {}); EXPECT_EQ(Vector->getTag(), dwarf::DW_TAG_array_type);