diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 18 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 27 |
4 files changed, 43 insertions, 16 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index e78bc5dcc4b..cbe00cb51ce 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1681,8 +1681,8 @@ static void writeMDNamespace(raw_ostream &Out, const MDNamespace *N, 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 << ")"; } @@ -1778,12 +1778,12 @@ static void writeMDObjCProperty(raw_ostream &Out, const MDObjCProperty *N, 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 << ")"; } @@ -1794,8 +1794,8 @@ static void writeMDImportedEntity(raw_ostream &Out, const MDImportedEntity *N, 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 << ")"; } diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 28d27d201c0..01b277991e9 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -734,7 +734,7 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, 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; diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index 70291b5aeaa..d9dd0551bdd 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -635,11 +635,11 @@ template <> struct MDNodeKeyImpl<MDNamespace> { 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 { @@ -789,15 +789,15 @@ template <> struct MDNodeKeyImpl<MDObjCProperty> { : 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, @@ -816,12 +816,12 @@ template <> struct MDNodeKeyImpl<MDImportedEntity> { 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 { diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index f4a0b679e55..a30fedd119d 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -303,6 +303,7 @@ private: 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; @@ -681,6 +682,15 @@ static bool isScopeRef(const Metadata *MD) { 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()) { @@ -890,15 +900,25 @@ void Verifier::visitMDLexicalBlockFile(const MDLexicalBlockFile &N) { 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, @@ -949,12 +969,19 @@ void Verifier::visitMDExpression(const MDExpression &N) { 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) { |