From 6643868498043d373384e0befaff3b5a8a8574f7 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 11 Mar 2013 23:21:19 +0000 Subject: [PATCH] Add asserts to DIBuilder & fix DINameSpace::Verify to allow unnamed namespaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176837 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/DIBuilder.cpp | 37 +++++++++++++++++++++++++++++++------ lib/IR/DebugInfo.cpp | 2 -- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index f31e531d47f..5ee36abc6b1 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -487,7 +487,9 @@ DIType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, DIType DerivedFrom, DIArray Elements, MDNode *VTableHolder, MDNode *TemplateParams) { - // TAG_class_type is encoded in DICompositeType format. + assert((!Context || Context.Verify()) && + "createClassType should be called with a valid Context"); + // TAG_class_type is encoded in DICompositeType format. Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_class_type), getNonCompileUnitScope(Context), @@ -504,7 +506,9 @@ DIType DIBuilder::createClassType(DIDescriptor Context, StringRef Name, VTableHolder, TemplateParams }; - return DIType(MDNode::get(VMContext, Elts)); + DIType R(MDNode::get(VMContext, Elts)); + assert(R.Verify() && "createClassType should return a verifiable DIType"); + return R; } /// createStructType - Create debugging information entry for a struct. @@ -534,7 +538,9 @@ DICompositeType DIBuilder::createStructType(DIDescriptor Context, VTableHolder, NULL, }; - return DICompositeType(MDNode::get(VMContext, Elts)); + DICompositeType R(MDNode::get(VMContext, Elts)); + assert(R.Verify() && "createStructType should return a verifiable DIType"); + return R; } /// createUnionType - Create debugging information entry for an union. @@ -766,6 +772,8 @@ DIType DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang) }; MDNode *Node = MDNode::getTemporary(VMContext, Elts); + assert(DIType(Node).Verify() && + "createForwardDecl result should be verifiable"); return DIType(Node); } @@ -846,6 +854,11 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, unsigned LineNo, DIType Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) { + DIDescriptor Context(getNonCompileUnitScope(Scope)); + assert((!Context || Context.Verify()) && + "createLocalVariable should be called with a valid Context"); + assert(Ty.Verify() && + "createLocalVariable should be called with a valid type"); Value *Elts[] = { GetTagConstant(VMContext, Tag), getNonCompileUnitScope(Scope), @@ -865,6 +878,8 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope, NamedMDNode *FnLocals = getOrInsertFnSpecificMDNode(M, Fn); FnLocals->addOperand(Node); } + assert(DIVariable(Node).Verify() && + "createLocalVariable should return a verifiable DIVariable"); return DIVariable(Node); } @@ -990,7 +1005,10 @@ DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name, File, ConstantInt::get(Type::getInt32Ty(VMContext), LineNo) }; - return DINameSpace(MDNode::get(VMContext, Elts)); + DINameSpace R(MDNode::get(VMContext, Elts)); + assert(R.Verify() && + "createNameSpace should return a verifiable DINameSpace"); + return R; } /// createLexicalBlockFile - This creates a new MDNode that encapsulates @@ -1002,7 +1020,11 @@ DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, Scope, File }; - return DILexicalBlockFile(MDNode::get(VMContext, Elts)); + DILexicalBlockFile R(MDNode::get(VMContext, Elts)); + assert( + R.Verify() && + "createLexicalBlockFile should return a verifiable DILexicalBlockFile"); + return R; } DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, @@ -1017,7 +1039,10 @@ DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, File, ConstantInt::get(Type::getInt32Ty(VMContext), unique_id++) }; - return DILexicalBlock(MDNode::get(VMContext, Elts)); + DILexicalBlock R(MDNode::get(VMContext, Elts)); + assert(R.Verify() && + "createLexicalBlock should return a verifiable DILexicalBlock"); + return R; } /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call. diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index a59fdcd4de9..9a5e47318ac 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -517,8 +517,6 @@ bool DILocation::Verify() const { bool DINameSpace::Verify() const { if (!DbgNode) return false; - if (getName().empty()) - return false; return true; }