From 9dc47c0c4a41e353d8f398df1848cddea37c2d59 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 21 Jan 2015 18:32:56 +0000 Subject: [PATCH] Let subprograms with instructions without parent scopes fail the verification. Tested via a unit test. Follow-up to r226616. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226684 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/DebugInfo.cpp | 3 ++- unittests/IR/IRBuilderTest.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 5dff50d362f..76836fd9551 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -536,7 +536,8 @@ bool DISubprogram::Verify() const { Scope = D.isLexicalBlockFile() ? D.getScope() : DebugLoc::getFromDILexicalBlock(Scope).getScope(); - assert(Scope && "lexical block file has no scope"); + if (!Scope) + return false; } if (!DISubprogram(Scope).describes(F)) return false; diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index df5c8406477..c8670f23cbe 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -10,6 +10,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DIBuilder.h" #include "llvm/IR/Function.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" @@ -287,5 +288,21 @@ TEST_F(IRBuilderTest, RAIIHelpersTest) { EXPECT_EQ(BB, Builder.GetInsertBlock()); } +TEST_F(IRBuilderTest, DIBuilder) { + IRBuilder<> Builder(BB); + DIBuilder DIB(*M); + auto File = DIB.createFile("F.CBL", "/"); + auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/", + "llvm-cobol74", true, "", 0); + auto Type = DIB.createSubroutineType(File, DIB.getOrCreateTypeArray({})); + auto SP = DIB.createFunction(CU, "foo", "", File, 1, Type, + false, true, 1, 0, true, F); + EXPECT_TRUE(SP.Verify()); + AllocaInst *I = Builder.CreateAlloca(Builder.getInt8Ty()); + auto BadScope = DIB.createLexicalBlockFile(DIDescriptor(), File, 0); + I->setDebugLoc(DebugLoc::get(2, 0, BadScope)); + EXPECT_FALSE(SP.Verify()); +} + }