Index: llvm/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/include/llvm/IR/DIBuilder.h +++ llvm/include/llvm/IR/DIBuilder.h @@ -494,8 +494,24 @@ /// \param AlignInBits Alignment. /// \param Ty Element type. /// \param Subscripts Subscripts. + /// \param DataLocation The location of the raw data of a descriptor-based + /// Fortran array. Typically a DIExpression* or + /// a DIVariable*. + /// \param Associated The associated attribute of a descriptor-based + /// Fortran array. Typically a DIExpression* or + /// a DIVariable*. + /// \param Allocated The allocated attribute of a descriptor-based + /// Fortran array. Typically a DIExpression* or + /// a DIVariable*. + /// \param Rank The rank attribute of a descriptor-based + /// Fortran array. Typically a DIExpression* or + /// a DIVariable*. DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits, - DIType *Ty, DINodeArray Subscripts); + DIType *Ty, DINodeArray Subscripts, + Metadata *DataLocation = nullptr, + Metadata *Associated = nullptr, + Metadata *Allocated = nullptr, + Metadata *Rank = nullptr); /// Create debugging information entry for a vector type. /// \param Size Array size. Index: llvm/lib/IR/DIBuilder.cpp =================================================================== --- llvm/lib/IR/DIBuilder.cpp +++ llvm/lib/IR/DIBuilder.cpp @@ -527,10 +527,16 @@ DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty, - DINodeArray Subscripts) { + DINodeArray Subscripts, + Metadata *DataLocation, + Metadata *Associated, + Metadata *Allocated, + Metadata *Rank) { auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, - DINode::FlagZero, Subscripts, 0, nullptr); + DINode::FlagZero, Subscripts, 0, nullptr, + nullptr, "", nullptr, DataLocation, + Associated, Allocated, Rank); trackIfUnresolved(R); return R; } Index: llvm/unittests/IR/DebugInfoTest.cpp =================================================================== --- llvm/unittests/IR/DebugInfoTest.cpp +++ llvm/unittests/IR/DebugInfoTest.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DIBuilder.h" #include "llvm/AsmParser/Parser.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/IntrinsicInst.h" @@ -185,4 +186,39 @@ EXPECT_TRUE(isa(DVIs[0]->getValue())); } +TEST(DIBuilder, CreateFortranArrayTypeWithAttributes) { + LLVMContext Ctx; + std::unique_ptr M(new Module("MyModule", Ctx)); + DIBuilder DIB(*M); + + DISubrange *Subrange = DIB.getOrCreateSubrange(1,1); + SmallVector Subranges; + Subranges.push_back(Subrange); + DINodeArray Subscripts = DIB.getOrCreateArray(Subranges); + + auto getDIExpression = [&DIB](int offset) { + SmallVector ops; + ops.push_back(llvm::dwarf::DW_OP_push_object_address); + DIExpression::appendOffset(ops, offset); + ops.push_back(llvm::dwarf::DW_OP_deref); + + return DIB.createExpression(ops); + }; + + DIExpression *DataLocation = getDIExpression(0); + DIExpression *Associated = getDIExpression(1); + DIExpression *Allocated = getDIExpression(2); + DIExpression *Rank = DIB.createConstantValueExpression(3); + + DICompositeType *ArrayType = DIB.createArrayType(0, 0, nullptr, Subscripts, + DataLocation, Associated, + Allocated, Rank); + + EXPECT_TRUE(isa_and_nonnull(ArrayType)); + EXPECT_EQ(ArrayType->getRawDataLocation(), DataLocation); + EXPECT_EQ(ArrayType->getRawAssociated(), Associated); + EXPECT_EQ(ArrayType->getRawAllocated(), Allocated); + EXPECT_EQ(ArrayType->getRawRank(), Rank); +} + } // end namespace