forked from OSchip/llvm-project
[DebugInfo] Expose Fortran array debug info attributes through DIBuilder.
The support of a few debug info attributes specifically for Fortran arrays have been added to LLVM recently, but there's no way to take advantage of them through DIBuilder. This patch extends DIBuilder::createArrayType to enable the settings of those attributes. Patch by Chih-Ping Chen! Differential Review: https://reviews.llvm.org/D90323
This commit is contained in:
parent
a6dd01afa3
commit
0b2b50a5d2
|
@ -494,8 +494,24 @@ namespace llvm {
|
|||
/// \param AlignInBits Alignment.
|
||||
/// \param Ty Element type.
|
||||
/// \param Subscripts Subscripts.
|
||||
DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits,
|
||||
DIType *Ty, DINodeArray 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(
|
||||
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
|
||||
PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
|
||||
PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
|
||||
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
|
||||
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
|
||||
|
||||
/// Create debugging information entry for a vector type.
|
||||
/// \param Size Array size.
|
||||
|
|
|
@ -525,12 +525,24 @@ DICompositeType *DIBuilder::createEnumerationType(
|
|||
return CTy;
|
||||
}
|
||||
|
||||
DICompositeType *DIBuilder::createArrayType(uint64_t Size,
|
||||
uint32_t AlignInBits, DIType *Ty,
|
||||
DINodeArray Subscripts) {
|
||||
auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
|
||||
nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
|
||||
DINode::FlagZero, Subscripts, 0, nullptr);
|
||||
DICompositeType *DIBuilder::createArrayType(
|
||||
uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
|
||||
PointerUnion<DIExpression *, DIVariable *> DL,
|
||||
PointerUnion<DIExpression *, DIVariable *> AS,
|
||||
PointerUnion<DIExpression *, DIVariable *> AL,
|
||||
PointerUnion<DIExpression *, DIVariable *> RK) {
|
||||
auto *R = DICompositeType::get(
|
||||
VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
|
||||
nullptr, Ty, Size, AlignInBits, 0, DINode::FlagZero,
|
||||
Subscripts, 0, nullptr, nullptr, "", nullptr,
|
||||
DL.is<DIExpression *>() ? (Metadata *)DL.get<DIExpression *>()
|
||||
: (Metadata *)DL.get<DIVariable *>(),
|
||||
AS.is<DIExpression *>() ? (Metadata *)AS.get<DIExpression *>()
|
||||
: (Metadata *)AS.get<DIVariable *>(),
|
||||
AL.is<DIExpression *>() ? (Metadata *)AL.get<DIExpression *>()
|
||||
: (Metadata *)AL.get<DIVariable *>(),
|
||||
RK.is<DIExpression *>() ? (Metadata *)RK.get<DIExpression *>()
|
||||
: (Metadata *)RK.get<DIVariable *>());
|
||||
trackIfUnresolved(R);
|
||||
return R;
|
||||
}
|
||||
|
|
|
@ -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,47 @@ TEST(MetadataTest, DeleteInstUsedByDbgValue) {
|
|||
EXPECT_TRUE(isa<UndefValue>(DVIs[0]->getValue()));
|
||||
}
|
||||
|
||||
TEST(DIBuilder, CreateFortranArrayTypeWithAttributes) {
|
||||
LLVMContext Ctx;
|
||||
std::unique_ptr<Module> M(new Module("MyModule", Ctx));
|
||||
DIBuilder DIB(*M);
|
||||
|
||||
DISubrange *Subrange = DIB.getOrCreateSubrange(1,1);
|
||||
SmallVector<Metadata*, 4> Subranges;
|
||||
Subranges.push_back(Subrange);
|
||||
DINodeArray Subscripts = DIB.getOrCreateArray(Subranges);
|
||||
|
||||
auto getDIExpression = [&DIB](int offset) {
|
||||
SmallVector<uint64_t, 4> 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);
|
||||
};
|
||||
|
||||
DIFile *F = DIB.createFile("main.c", "/");
|
||||
DICompileUnit *CU = DIB.createCompileUnit(
|
||||
dwarf::DW_LANG_C, DIB.createFile("main.c", "/"), "llvm-c", true, "", 0);
|
||||
|
||||
DIVariable *DataLocation =
|
||||
DIB.createTempGlobalVariableFwdDecl(CU, "dl", "_dl", F, 1, nullptr, true);
|
||||
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<DICompositeType>(ArrayType));
|
||||
EXPECT_EQ(ArrayType->getRawDataLocation(), DataLocation);
|
||||
EXPECT_EQ(ArrayType->getRawAssociated(), Associated);
|
||||
EXPECT_EQ(ArrayType->getRawAllocated(), Allocated);
|
||||
EXPECT_EQ(ArrayType->getRawRank(), Rank);
|
||||
|
||||
// Avoid memory leak.
|
||||
DIVariable::deleteTemporary(DataLocation);
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
Loading…
Reference in New Issue