~MDScope() {}
public:
- // FIXME: Downcast to MDFile once we've verified all subclasses.
- Metadata *getFile() const { return getRawFile(); }
+ MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
/// \brief Return the raw underlying file.
///
uint64_t getOffsetInBits() const { return OffsetInBits; }
unsigned getFlags() const { return Flags; }
- // FIXME: Remove this once MDScope::getFile() does the same.
- MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
-
Metadata *getScope() const { return getRawScope(); }
StringRef getName() const { return getStringOperand(2); }
TempMDCompileUnit clone() const { return cloneImpl(); }
- // FIXME: Remove this once MDScope::getFile() does the same.
- MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
-
unsigned getSourceLanguage() const { return SourceLanguage; }
bool isOptimized() const { return IsOptimized; }
unsigned getRuntimeVersion() const { return RuntimeVersion; }
bool isDefinition() const { return IsDefinition; }
bool isOptimized() const { return IsOptimized; }
- // FIXME: Remove this once MDScope::getFile() does the same.
- MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
-
Metadata *getScope() const { return getRawScope(); }
StringRef getName() const { return getStringOperand(2); }
~MDLexicalBlockBase() {}
public:
- // FIXME: Remove this once MDScope::getFile() does the same.
- MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
-
MDLocalScope *getScope() const { return cast<MDLocalScope>(getRawScope()); }
Metadata *getRawScope() const { return getOperand(1); }
Line(Line) {}
~MDNamespace() {}
- static MDNamespace *getImpl(LLVMContext &Context, Metadata *Scope,
- Metadata *File, StringRef Name, unsigned Line,
+ static MDNamespace *getImpl(LLVMContext &Context, MDScope *Scope,
+ MDFile *File, StringRef Name, unsigned Line,
StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, File, getCanonicalMDString(Context, Name),
Line, Storage, ShouldCreate);
}
public:
- DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
- StringRef Name, unsigned Line),
+ DEFINE_MDNODE_GET(MDNamespace, (MDScope * Scope, MDFile *File, StringRef Name,
+ unsigned Line),
(Scope, File, Name, Line))
DEFINE_MDNODE_GET(MDNamespace, (Metadata * Scope, Metadata *File,
MDString *Name, unsigned Line),
TempMDNamespace clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
- Metadata *getScope() const { return getOperand(1); }
+ MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(2); }
+ Metadata *getRawScope() const { return getOperand(1); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
static bool classof(const Metadata *MD) {
~MDObjCProperty() {}
static MDObjCProperty *
- getImpl(LLVMContext &Context, StringRef Name, Metadata *File, unsigned Line,
+ getImpl(LLVMContext &Context, StringRef Name, MDFile *File, unsigned Line,
StringRef GetterName, StringRef SetterName, unsigned Attributes,
- Metadata *Type, StorageType Storage, bool ShouldCreate = true) {
+ MDType *Type, StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, getCanonicalMDString(Context, Name), File, Line,
getCanonicalMDString(Context, GetterName),
getCanonicalMDString(Context, SetterName), Attributes, Type,
public:
DEFINE_MDNODE_GET(MDObjCProperty,
- (StringRef Name, Metadata *File, unsigned Line,
+ (StringRef Name, MDFile *File, unsigned Line,
StringRef GetterName, StringRef SetterName,
- unsigned Attributes, Metadata *Type),
+ unsigned Attributes, MDType *Type),
(Name, File, Line, GetterName, SetterName, Attributes,
Type))
DEFINE_MDNODE_GET(MDObjCProperty,
unsigned getLine() const { return Line; }
unsigned getAttributes() const { return Attributes; }
StringRef getName() const { return getStringOperand(0); }
- Metadata *getFile() const { return getOperand(1); }
+ MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
StringRef getGetterName() const { return getStringOperand(2); }
StringRef getSetterName() const { return getStringOperand(3); }
- Metadata *getType() const { return getOperand(4); }
+ MDType *getType() const { return cast_or_null<MDType>(getRawType()); }
MDString *getRawName() const { return getOperandAs<MDString>(0); }
+ Metadata *getRawFile() const { return getOperand(1); }
MDString *getRawGetterName() const { return getOperandAs<MDString>(2); }
MDString *getRawSetterName() const { return getOperandAs<MDString>(3); }
+ Metadata *getRawType() const { return getOperand(4); }
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDObjCPropertyKind;
~MDImportedEntity() {}
static MDImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
- Metadata *Scope, Metadata *Entity,
+ MDScope *Scope, Metadata *Entity,
unsigned Line, StringRef Name,
StorageType Storage,
bool ShouldCreate = true) {
public:
DEFINE_MDNODE_GET(MDImportedEntity,
- (unsigned Tag, Metadata *Scope, Metadata *Entity,
+ (unsigned Tag, MDScope *Scope, Metadata *Entity,
unsigned Line, StringRef Name = ""),
(Tag, Scope, Entity, Line, Name))
DEFINE_MDNODE_GET(MDImportedEntity,
TempMDImportedEntity clone() const { return cloneImpl(); }
unsigned getLine() const { return Line; }
- Metadata *getScope() const { return getOperand(0); }
- Metadata *getEntity() const { return getOperand(1); }
+ MDScope *getScope() const { return cast_or_null<MDScope>(getRawScope()); }
+ Metadata *getEntity() const { return getRawEntity(); }
StringRef getName() const { return getStringOperand(2); }
+ Metadata *getRawScope() const { return getOperand(0); }
+ Metadata *getRawEntity() const { return getOperand(1); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
static bool classof(const Metadata *MD) {
Out << "!MDNamespace(";
MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
Printer.printString("name", N->getName());
- Printer.printMetadata("scope", N->getScope(), /* ShouldSkipNull */ false);
- Printer.printMetadata("file", N->getFile());
+ Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
+ Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
Out << ")";
}
Out << "!MDObjCProperty(";
MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
Printer.printString("name", N->getName());
- Printer.printMetadata("file", N->getFile());
+ Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
Printer.printString("setter", N->getSetterName());
Printer.printString("getter", N->getGetterName());
Printer.printInt("attributes", N->getAttributes());
- Printer.printMetadata("type", N->getType());
+ Printer.printMetadata("type", N->getRawType());
Out << ")";
}
MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
Printer.printTag(N);
Printer.printString("name", N->getName());
- Printer.printMetadata("scope", N->getScope(), /* ShouldSkipNull */ false);
- Printer.printMetadata("entity", N->getEntity());
+ Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
+ Printer.printMetadata("entity", N->getRawEntity());
Printer.printInt("line", N->getLine());
Out << ")";
}
DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
DIFile File, unsigned LineNo) {
DINameSpace R = MDNamespace::get(VMContext, getNonCompileUnitScope(Scope),
- File.getFileNode(), Name, LineNo);
+ File, Name, LineNo);
assert(R.Verify() &&
"createNameSpace should return a verifiable DINameSpace");
return R;
MDNodeKeyImpl(Metadata *Scope, Metadata *File, StringRef Name, unsigned Line)
: Scope(Scope), File(File), Name(Name), Line(Line) {}
MDNodeKeyImpl(const MDNamespace *N)
- : Scope(N->getScope()), File(N->getFile()), Name(N->getName()),
+ : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getName()),
Line(N->getLine()) {}
bool isKeyOf(const MDNamespace *RHS) const {
- return Scope == RHS->getScope() && File == RHS->getFile() &&
+ return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Name == RHS->getName() && Line == RHS->getLine();
}
unsigned getHashValue() const {
: Name(Name), File(File), Line(Line), GetterName(GetterName),
SetterName(SetterName), Attributes(Attributes), Type(Type) {}
MDNodeKeyImpl(const MDObjCProperty *N)
- : Name(N->getName()), File(N->getFile()), Line(N->getLine()),
+ : Name(N->getName()), File(N->getRawFile()), Line(N->getLine()),
GetterName(N->getGetterName()), SetterName(N->getSetterName()),
- Attributes(N->getAttributes()), Type(N->getType()) {}
+ Attributes(N->getAttributes()), Type(N->getRawType()) {}
bool isKeyOf(const MDObjCProperty *RHS) const {
- return Name == RHS->getName() && File == RHS->getFile() &&
+ return Name == RHS->getName() && File == RHS->getRawFile() &&
Line == RHS->getLine() && GetterName == RHS->getGetterName() &&
SetterName == RHS->getSetterName() &&
- Attributes == RHS->getAttributes() && Type == RHS->getType();
+ Attributes == RHS->getAttributes() && Type == RHS->getRawType();
}
unsigned getHashValue() const {
return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
StringRef Name)
: Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
MDNodeKeyImpl(const MDImportedEntity *N)
- : Tag(N->getTag()), Scope(N->getScope()), Entity(N->getEntity()),
+ : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Line(N->getLine()), Name(N->getName()) {}
bool isKeyOf(const MDImportedEntity *RHS) const {
- return Tag == RHS->getTag() && Scope == RHS->getScope() &&
- Entity == RHS->getEntity() && Line == RHS->getLine() &&
+ return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
+ Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Name == RHS->getName();
}
unsigned getHashValue() const {
void visitMDDerivedTypeBase(const MDDerivedTypeBase &N);
void visitMDVariable(const MDVariable &N);
void visitMDLexicalBlockBase(const MDLexicalBlockBase &N);
+ void visitMDTemplateParameter(const MDTemplateParameter &N);
// InstVisitor overrides...
using InstVisitor<Verifier>::visit;
return isa<MDScope>(MD);
}
+/// \brief Check if a value can be a debug info ref.
+static bool isDIRef(const Metadata *MD) {
+ if (!MD)
+ return true;
+ if (auto *S = dyn_cast<MDString>(MD))
+ return !S->getString().empty();
+ return isa<DebugNode>(MD);
+}
+
template <class Ty>
bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull) {
for (Metadata *MD : N.operands()) {
void Verifier::visitMDNamespace(const MDNamespace &N) {
Assert(N.getTag() == dwarf::DW_TAG_namespace, "invalid tag", &N);
+ if (auto *S = N.getRawScope())
+ Assert(isa<MDScope>(S), "invalid scope ref", &N, S);
+}
+
+void Verifier::visitMDTemplateParameter(const MDTemplateParameter &N) {
+ Assert(isTypeRef(N.getType()), "invalid type ref", &N, N.getType());
}
void Verifier::visitMDTemplateTypeParameter(const MDTemplateTypeParameter &N) {
+ visitMDTemplateParameter(N);
+
Assert(N.getTag() == dwarf::DW_TAG_template_type_parameter, "invalid tag",
&N);
}
void Verifier::visitMDTemplateValueParameter(
const MDTemplateValueParameter &N) {
+ visitMDTemplateParameter(N);
+
Assert(N.getTag() == dwarf::DW_TAG_template_value_parameter ||
N.getTag() == dwarf::DW_TAG_GNU_template_template_param ||
N.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack,
void Verifier::visitMDObjCProperty(const MDObjCProperty &N) {
Assert(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N);
+ if (auto *T = N.getRawType())
+ Assert(isa<MDType>(T), "invalid type ref", &N, T);
+ if (auto *F = N.getRawFile())
+ Assert(isa<MDFile>(F), "invalid file", &N, F);
}
void Verifier::visitMDImportedEntity(const MDImportedEntity &N) {
Assert(N.getTag() == dwarf::DW_TAG_imported_module ||
N.getTag() == dwarf::DW_TAG_imported_declaration,
"invalid tag", &N);
+ if (auto *S = N.getRawScope())
+ Assert(isa<MDScope>(S), "invalid scope for imported entity", &N, S);
+ Assert(isDIRef(N.getEntity()), "invalid imported entity", &N, N.getEntity());
}
void Verifier::visitComdat(const Comdat &C) {
; CHECK: !named = !{!0, !1, !2, !3, !3}
!named = !{!0, !1, !2, !3, !4}
-; CHECK: !0 = distinct !{}
-; CHECK-NEXT: !1 = distinct !{}
-!0 = distinct !{}
-!1 = distinct !{}
+; CHECK: !0 = !MDSubprogram({{.*}})
+; CHECK-NEXT: !1 = !MDCompositeType({{.*}})
+!0 = !MDSubprogram(name: "foo")
+!1 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Class", size: 32, align: 32)
; CHECK-NEXT: !2 = !MDImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0, entity: !1, line: 7)
!2 = !MDImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
; CHECK: !named = !{!0, !1, !2, !3, !4, !4}
!named = !{!0, !1, !2, !3, !4, !5}
-!0 = distinct !{}
+!0 = !MDFile(filename: "file.cpp", directory: "/path/to/dir")
!1 = distinct !{}
!2 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
!0 = distinct !{}
!1 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
-!2 = distinct !{}
+!2 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Object")
-
-; CHECK: !2 = distinct !{}
+; CHECK: !2 = !MDCompositeType({{.*}})
; CHECK-NEXT: !3 = !MDObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo", getter: "getFoo", attributes: 7, type: !2)
!3 = !MDObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
getter: "getFoo", attributes: 7, type: !2)
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
!0 = distinct !{}
-!1 = distinct !{}
-; CHECK: !1 = distinct !{}
+!1 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+; CHECK: !1 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
; CHECK-NEXT: !2 = !MDTemplateTypeParameter(name: "Ty", type: !1)
; CHECK-NEXT: !3 = !MDTemplateTypeParameter(type: !1)
typedef MetadataTest MDNamespaceTest;
TEST_F(MDNamespaceTest, get) {
- Metadata *Scope = MDTuple::getDistinct(Context, None);
- Metadata *File = MDTuple::getDistinct(Context, None);
+ MDScope *Scope = getFile();
+ MDFile *File = getFile();
StringRef Name = "namespace";
unsigned Line = 5;
EXPECT_EQ(Line, N->getLine());
EXPECT_EQ(N, MDNamespace::get(Context, Scope, File, Name, Line));
- EXPECT_NE(N, MDNamespace::get(Context, File, File, Name, Line));
- EXPECT_NE(N, MDNamespace::get(Context, Scope, Scope, Name, Line));
+ EXPECT_NE(N, MDNamespace::get(Context, getFile(), File, Name, Line));
+ EXPECT_NE(N, MDNamespace::get(Context, Scope, getFile(), Name, Line));
EXPECT_NE(N, MDNamespace::get(Context, Scope, File, "other", Line));
EXPECT_NE(N, MDNamespace::get(Context, Scope, File, Name, Line + 1));
TEST_F(MDTemplateTypeParameterTest, get) {
StringRef Name = "template";
- Metadata *Type = MDTuple::getDistinct(Context, None);
- Metadata *Other = MDTuple::getDistinct(Context, None);
+ MDType *Type = getBasicType("basic");
auto *N = MDTemplateTypeParameter::get(Context, Name, Type);
EXPECT_EQ(N, MDTemplateTypeParameter::get(Context, Name, Type));
EXPECT_NE(N, MDTemplateTypeParameter::get(Context, "other", Type));
- EXPECT_NE(N, MDTemplateTypeParameter::get(Context, Name, Other));
+ EXPECT_NE(N,
+ MDTemplateTypeParameter::get(Context, Name, getBasicType("other")));
TempMDTemplateTypeParameter Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
TEST_F(MDTemplateValueParameterTest, get) {
unsigned Tag = dwarf::DW_TAG_template_value_parameter;
StringRef Name = "template";
- Metadata *Type = MDTuple::getDistinct(Context, None);
- Metadata *Value = MDTuple::getDistinct(Context, None);
- Metadata *Other = MDTuple::getDistinct(Context, None);
+ MDType *Type = getBasicType("basic");
+ Metadata *Value = getConstantAsMetadata();
auto *N = MDTemplateValueParameter::get(Context, Tag, Name, Type, Value);
EXPECT_EQ(Tag, N->getTag());
Type, Value));
EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, "other", Type,
Value));
- EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Other,
- Value));
- EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Type, Other));
+ EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name,
+ getBasicType("other"), Value));
+ EXPECT_NE(N, MDTemplateValueParameter::get(Context, Tag, Name, Type,
+ getConstantAsMetadata()));
TempMDTemplateValueParameter Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
TEST_F(MDObjCPropertyTest, get) {
StringRef Name = "name";
- Metadata *File = MDTuple::getDistinct(Context, None);
+ MDFile *File = getFile();
unsigned Line = 5;
StringRef GetterName = "getter";
StringRef SetterName = "setter";
unsigned Attributes = 7;
- Metadata *Type = MDTuple::getDistinct(Context, None);
+ MDType *Type = getBasicType("basic");
auto *N = MDObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes, Type);
EXPECT_NE(N, MDObjCProperty::get(Context, "other", File, Line, GetterName,
SetterName, Attributes, Type));
- EXPECT_NE(N, MDObjCProperty::get(Context, Name, Type, Line, GetterName,
+ EXPECT_NE(N, MDObjCProperty::get(Context, Name, getFile(), Line, GetterName,
SetterName, Attributes, Type));
EXPECT_NE(N, MDObjCProperty::get(Context, Name, File, Line + 1, GetterName,
SetterName, Attributes, Type));
"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, File));
+ EXPECT_NE(N,
+ MDObjCProperty::get(Context, Name, File, Line, GetterName,
+ SetterName, Attributes, getBasicType("other")));
TempMDObjCProperty Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
TEST_F(MDImportedEntityTest, get) {
unsigned Tag = dwarf::DW_TAG_imported_module;
- Metadata *Scope = MDTuple::getDistinct(Context, None);
- Metadata *Entity = MDTuple::getDistinct(Context, None);
+ MDScope *Scope = getSubprogram();
+ DebugNode *Entity = getCompositeType();
unsigned Line = 5;
StringRef Name = "name";
EXPECT_NE(N,
MDImportedEntity::get(Context, dwarf::DW_TAG_imported_declaration,
Scope, Entity, Line, Name));
- EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Entity, Entity, Line, Name));
- EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, Scope, Line, Name));
+ EXPECT_NE(N, MDImportedEntity::get(Context, Tag, getSubprogram(), Entity,
+ Line, Name));
+ EXPECT_NE(N, MDImportedEntity::get(Context, Tag, Scope, getCompositeType(),
+ Line, Name));
EXPECT_NE(N,
MDImportedEntity::get(Context, Tag, Scope, Entity, Line + 1, Name));
EXPECT_NE(N,