DebugInfo: Use MDTypeRef throughout the hierarchy

Use `MDTypeRef` (etc.) in the new debug info hierarchy rather than raw
`Metadata *` pointers.

I rolled in a change to `DIBuilder` that looks unrelated: take `DIType`
instead of `DITypeRef` as type arguments when creating variables.
However, this was the simplest way to use `MDTypeRef` within the
functions, and didn't require any cleanups from callers in clang (since
they were all passing in `DIType`s anyway, relying on their implicit
conversions to `DITypeRef`).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234197 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-04-06 19:03:45 +00:00
parent ebb3c53316
commit e009b6fd92
8 changed files with 206 additions and 186 deletions

View File

@ -85,25 +85,29 @@ protected:
nullptr, false, false, 0, nullptr, 0, 0, 0,
0);
}
MDScopeRef getSubprogramRef() { return getSubprogram()->getRef(); }
MDFile *getFile() {
return MDFile::getDistinct(Context, "file.c", "/path/to/dir");
}
MDBasicType *getBasicType(StringRef Name) {
return MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
MDTypeRef getBasicType(StringRef Name) {
return MDBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name)
->getRef();
}
MDDerivedType *getDerivedType() {
MDTypeRef getDerivedType() {
return MDDerivedType::getDistinct(Context, dwarf::DW_TAG_pointer_type, "",
nullptr, 0, nullptr,
getBasicType("basictype"), 1, 2, 0, 0);
getBasicType("basictype"), 1, 2, 0, 0)
->getRef();
}
ConstantAsMetadata *getConstantAsMetadata() {
return ConstantAsMetadata::get(
ConstantInt::get(Type::getInt32Ty(Context), Counter++));
}
MDCompositeType *getCompositeType() {
MDTypeRef getCompositeType() {
return MDCompositeType::getDistinct(
Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr, nullptr,
32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "");
Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr,
nullptr, 32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "")
->getRef();
}
ConstantAsMetadata *getFunctionAsMetadata(StringRef Name) {
return ConstantAsMetadata::get(M.getOrInsertFunction(
@ -958,8 +962,8 @@ typedef MetadataTest MDDerivedTypeTest;
TEST_F(MDDerivedTypeTest, get) {
MDFile *File = getFile();
MDScope *Scope = getSubprogram();
MDType *BaseType = getBasicType("basic");
MDScopeRef Scope = getSubprogramRef();
MDTypeRef BaseType = getBasicType("basic");
MDTuple *ExtraData = getTuple();
auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
@ -992,7 +996,7 @@ TEST_F(MDDerivedTypeTest, get) {
"something", File, 2, Scope, BaseType, 2, 3,
4, 5, ExtraData));
EXPECT_NE(N, MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type,
"something", File, 1, getSubprogram(),
"something", File, 1, getSubprogramRef(),
BaseType, 2, 3, 4, 5, ExtraData));
EXPECT_NE(N, MDDerivedType::get(
Context, dwarf::DW_TAG_pointer_type, "something", File, 1,
@ -1019,8 +1023,8 @@ TEST_F(MDDerivedTypeTest, get) {
TEST_F(MDDerivedTypeTest, getWithLargeValues) {
MDFile *File = getFile();
MDScope *Scope = getSubprogram();
MDType *BaseType = getBasicType("basic");
MDScopeRef Scope = getSubprogramRef();
MDTypeRef BaseType = getBasicType("basic");
MDTuple *ExtraData = getTuple();
auto *N = MDDerivedType::get(Context, dwarf::DW_TAG_pointer_type, "something",
@ -1038,15 +1042,15 @@ TEST_F(MDCompositeTypeTest, get) {
StringRef Name = "some name";
MDFile *File = getFile();
unsigned Line = 1;
MDScope *Scope = getSubprogram();
MDType *BaseType = getCompositeType();
MDScopeRef Scope = getSubprogramRef();
MDTypeRef BaseType = getCompositeType();
uint64_t SizeInBits = 2;
uint64_t AlignInBits = 3;
uint64_t OffsetInBits = 4;
unsigned Flags = 5;
MDTuple *Elements = getTuple();
unsigned RuntimeLang = 6;
MDType *VTableHolder = getCompositeType();
MDTypeRef VTableHolder = getCompositeType();
MDTuple *TemplateParams = getTuple();
StringRef Identifier = "some id";
@ -1092,13 +1096,13 @@ TEST_F(MDCompositeTypeTest, get) {
OffsetInBits, Flags, Elements, RuntimeLang,
VTableHolder, TemplateParams, Identifier));
EXPECT_NE(N, MDCompositeType::get(
Context, Tag, Name, File, Line, getSubprogram(), BaseType,
Context, Tag, Name, File, Line, getSubprogramRef(), BaseType,
SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
RuntimeLang, VTableHolder, TemplateParams, Identifier));
EXPECT_NE(N, MDCompositeType::get(
Context, Tag, Name, File, Line, Scope, getBasicType("other"),
SizeInBits, AlignInBits, OffsetInBits, Flags, Elements,
RuntimeLang, VTableHolder, TemplateParams, Identifier));
EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope, File,
SizeInBits, AlignInBits, OffsetInBits,
Flags, Elements, RuntimeLang, VTableHolder,
TemplateParams, Identifier));
EXPECT_NE(N, MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
BaseType, SizeInBits + 1, AlignInBits,
OffsetInBits, Flags, Elements, RuntimeLang,
@ -1155,15 +1159,15 @@ TEST_F(MDCompositeTypeTest, getWithLargeValues) {
StringRef Name = "some name";
MDFile *File = getFile();
unsigned Line = 1;
MDScope *Scope = getSubprogram();
MDType *BaseType = getCompositeType();
MDScopeRef Scope = getSubprogramRef();
MDTypeRef BaseType = getCompositeType();
uint64_t SizeInBits = UINT64_MAX;
uint64_t AlignInBits = UINT64_MAX - 1;
uint64_t OffsetInBits = UINT64_MAX - 2;
unsigned Flags = 5;
MDTuple *Elements = getTuple();
unsigned RuntimeLang = 6;
MDType *VTableHolder = getCompositeType();
MDTypeRef VTableHolder = getCompositeType();
MDTuple *TemplateParams = getTuple();
StringRef Identifier = "some id";
@ -1181,8 +1185,8 @@ TEST_F(MDCompositeTypeTest, replaceOperands) {
StringRef Name = "some name";
MDFile *File = getFile();
unsigned Line = 1;
MDScope *Scope = getSubprogram();
MDType *BaseType = getCompositeType();
MDScopeRef Scope = getSubprogramRef();
MDTypeRef BaseType = getCompositeType();
uint64_t SizeInBits = 2;
uint64_t AlignInBits = 3;
uint64_t OffsetInBits = 4;
@ -1202,7 +1206,7 @@ TEST_F(MDCompositeTypeTest, replaceOperands) {
N->replaceElements(nullptr);
EXPECT_EQ(nullptr, N->getElements());
auto *VTableHolder = MDTuple::getDistinct(Context, None);
MDTypeRef VTableHolder = getCompositeType();
EXPECT_EQ(nullptr, N->getVTableHolder());
N->replaceVTableHolder(VTableHolder);
EXPECT_EQ(VTableHolder, N->getVTableHolder());
@ -1413,7 +1417,7 @@ TEST_F(MDCompileUnitTest, replaceArrays) {
typedef MetadataTest MDSubprogramTest;
TEST_F(MDSubprogramTest, get) {
MDScope *Scope = getCompositeType();
MDScopeRef Scope = getCompositeType();
StringRef Name = "name";
StringRef LinkageName = "linkage";
MDFile *File = getFile();
@ -1422,7 +1426,7 @@ TEST_F(MDSubprogramTest, get) {
bool IsLocalToUnit = false;
bool IsDefinition = true;
unsigned ScopeLine = 3;
MDType *ContainingType = getCompositeType();
MDTypeRef ContainingType = getCompositeType();
unsigned Virtuality = 4;
unsigned VirtualIndex = 5;
unsigned Flags = 6;
@ -1559,7 +1563,7 @@ TEST_F(MDSubprogramTest, get) {
}
TEST_F(MDSubprogramTest, replaceFunction) {
MDScope *Scope = getCompositeType();
MDScopeRef Scope = getCompositeType();
StringRef Name = "name";
StringRef LinkageName = "linkage";
MDFile *File = getFile();
@ -1568,7 +1572,7 @@ TEST_F(MDSubprogramTest, replaceFunction) {
bool IsLocalToUnit = false;
bool IsDefinition = true;
unsigned ScopeLine = 3;
MDCompositeType *ContainingType = getCompositeType();
MDTypeRef ContainingType = getCompositeType();
unsigned Virtuality = 4;
unsigned VirtualIndex = 5;
unsigned Flags = 6;
@ -1677,7 +1681,7 @@ typedef MetadataTest MDTemplateTypeParameterTest;
TEST_F(MDTemplateTypeParameterTest, get) {
StringRef Name = "template";
MDType *Type = getBasicType("basic");
MDTypeRef Type = getBasicType("basic");
auto *N = MDTemplateTypeParameter::get(Context, Name, Type);
@ -1699,7 +1703,7 @@ typedef MetadataTest MDTemplateValueParameterTest;
TEST_F(MDTemplateValueParameterTest, get) {
unsigned Tag = dwarf::DW_TAG_template_value_parameter;
StringRef Name = "template";
MDType *Type = getBasicType("basic");
MDTypeRef Type = getBasicType("basic");
Metadata *Value = getConstantAsMetadata();
auto *N = MDTemplateValueParameter::get(Context, Tag, Name, Type, Value);
@ -1731,11 +1735,12 @@ TEST_F(MDGlobalVariableTest, get) {
StringRef LinkageName = "linkage";
MDFile *File = getFile();
unsigned Line = 5;
Metadata *Type = MDTuple::getDistinct(Context, None);
MDTypeRef Type = getDerivedType();
bool IsLocalToUnit = false;
bool IsDefinition = true;
ConstantAsMetadata *Variable = getConstantAsMetadata();
MDDerivedType *StaticDataMemberDeclaration = getDerivedType();
MDDerivedType *StaticDataMemberDeclaration =
cast<MDDerivedType>(getDerivedType());
auto *N = MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, Variable,
@ -1773,9 +1778,10 @@ TEST_F(MDGlobalVariableTest, get) {
MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line + 1, Type, IsLocalToUnit, IsDefinition,
Variable, StaticDataMemberDeclaration));
EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Scope, IsLocalToUnit, IsDefinition,
Variable, StaticDataMemberDeclaration));
EXPECT_NE(N,
MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
getDerivedType(), IsLocalToUnit, IsDefinition,
Variable, StaticDataMemberDeclaration));
EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, !IsLocalToUnit, IsDefinition,
Variable, StaticDataMemberDeclaration));
@ -1786,9 +1792,10 @@ TEST_F(MDGlobalVariableTest, get) {
Line, Type, IsLocalToUnit, IsDefinition,
getConstantAsMetadata(),
StaticDataMemberDeclaration));
EXPECT_NE(N, MDGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition,
Variable, getDerivedType()));
EXPECT_NE(N,
MDGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, Variable,
cast<MDDerivedType>(getDerivedType())));
TempMDGlobalVariable Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@ -1802,7 +1809,7 @@ TEST_F(MDLocalVariableTest, get) {
StringRef Name = "name";
MDFile *File = getFile();
unsigned Line = 5;
Metadata *Type = MDTuple::getDistinct(Context, None);
MDTypeRef Type = getDerivedType();
unsigned Arg = 6;
unsigned Flags = 7;
MDLocation *InlinedAt =
@ -1834,7 +1841,7 @@ TEST_F(MDLocalVariableTest, get) {
EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line + 1,
Type, Arg, Flags, InlinedAt));
EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line,
Scope, Arg, Flags, InlinedAt));
getDerivedType(), Arg, Flags, InlinedAt));
EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
Arg + 1, Flags, InlinedAt));
EXPECT_NE(N, MDLocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
@ -1924,7 +1931,7 @@ TEST_F(MDObjCPropertyTest, get) {
StringRef GetterName = "getter";
StringRef SetterName = "setter";
unsigned Attributes = 7;
MDType *Type = getBasicType("basic");
MDType *Type = cast<MDBasicType>(getBasicType("basic"));
auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes, Type);
@ -1952,9 +1959,9 @@ TEST_F(MDObjCPropertyTest, get) {
"other", Attributes, Type));
EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes + 1, Type));
EXPECT_NE(N,
MDObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes, getBasicType("other")));
EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes,
cast<MDBasicType>(getBasicType("other"))));
TempMDObjCProperty Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@ -1965,7 +1972,7 @@ typedef MetadataTest MDImportedEntityTest;
TEST_F(MDImportedEntityTest, get) {
unsigned Tag = dwarf::DW_TAG_imported_module;
MDScope *Scope = getSubprogram();
DebugNode *Entity = getCompositeType();
DebugNodeRef Entity = getCompositeType();
unsigned Line = 5;
StringRef Name = "name";