Skip to content

Verifier: Mark orphaned DICompileUnits as a debug info failure. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,9 +2035,9 @@ void Verifier::visitFunction(const Function &F) {
continue;

// FIXME: Once N is canonical, check "SP == &N".
Assert(SP->describes(&F),
"!dbg attachment points at wrong subprogram for function", N, &F,
&I, DL, Scope, SP);
AssertDI(SP->describes(&F),
"!dbg attachment points at wrong subprogram for function", N, &F,
&I, DL, Scope, SP);
}
}

Expand Down Expand Up @@ -4205,10 +4205,10 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
if (!VarSP || !LocSP)
return; // Broken scope chains are checked elsewhere.

Assert(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +
" variable and !dbg attachment",
&DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,
Loc->getScope()->getSubprogram());
AssertDI(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +
" variable and !dbg attachment",
&DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,
Loc->getScope()->getSubprogram());
}

static uint64_t getVariableSize(const DILocalVariable &V) {
Expand Down Expand Up @@ -4271,17 +4271,17 @@ void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I) {

unsigned PieceSize = E->getBitPieceSize();
unsigned PieceOffset = E->getBitPieceOffset();
Assert(PieceSize + PieceOffset <= VarSize,
AssertDI(PieceSize + PieceOffset <= VarSize,
"piece is larger than or outside of variable", &I, V, E);
Assert(PieceSize != VarSize, "piece covers entire variable", &I, V, E);
AssertDI(PieceSize != VarSize, "piece covers entire variable", &I, V, E);
}

void Verifier::verifyCompileUnits() {
auto *CUs = M->getNamedMetadata("llvm.dbg.cu");
SmallPtrSet<const Metadata *, 2> Listed;
if (CUs)
Listed.insert(CUs->op_begin(), CUs->op_end());
Assert(
AssertDI(
std::all_of(CUVisited.begin(), CUVisited.end(),
[&Listed](const Metadata *CU) { return Listed.count(CU); }),
"All DICompileUnits must be listed in llvm.dbg.cu");
Expand Down
73 changes: 53 additions & 20 deletions unittests/IR/VerifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -146,26 +147,58 @@ TEST(VerifierTest, CrossModuleMetadataRef) {
}

TEST(VerifierTest, StripInvalidDebugInfo) {
LLVMContext C;
Module M("M", C);
DIBuilder DIB(M);
DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/",
"unittest", false, "", 0);
DIB.finalize();
EXPECT_FALSE(verifyModule(M));

// Now break it.
auto *File = DIB.createFile("not-a-CU.f", ".");
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
NMD->addOperand(File);
EXPECT_TRUE(verifyModule(M));

ModulePassManager MPM(true);
MPM.addPass(VerifierPass(false));
ModuleAnalysisManager MAM(true);
MAM.registerPass(VerifierAnalysis());
MPM.run(M, &MAM);
EXPECT_FALSE(verifyModule(M));
{
LLVMContext C;
Module M("M", C);
DIBuilder DIB(M);
DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/", "unittest",
false, "", 0);
DIB.finalize();
EXPECT_FALSE(verifyModule(M));

// Now break it by inserting non-CU node to the list of CUs.
auto *File = DIB.createFile("not-a-CU.f", ".");
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
NMD->addOperand(File);
EXPECT_TRUE(verifyModule(M));

ModulePassManager MPM(true);
MPM.addPass(VerifierPass(false));
ModuleAnalysisManager MAM(true);
MAM.registerPass(VerifierAnalysis());
MPM.run(M, &MAM);
EXPECT_FALSE(verifyModule(M));
}
{
LLVMContext C;
Module M("M", C);
DIBuilder DIB(M);
auto *CU = DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/",
"unittest", false, "", 0);
new GlobalVariable(M, Type::getInt8Ty(C), false,
GlobalValue::ExternalLinkage, nullptr, "g");

auto *F = cast<Function>(M.getOrInsertFunction(
"f", FunctionType::get(Type::getVoidTy(C), false)));
IRBuilder<> Builder(BasicBlock::Create(C, "", F));
Builder.CreateUnreachable();
F->setSubprogram(DIB.createFunction(CU, "f", "f",
DIB.createFile("broken.c", "/"), 1,
nullptr, true, true, 1));
DIB.finalize();
EXPECT_FALSE(verifyModule(M));

// Now break it by not listing the CU at all.
M.eraseNamedMetadata(M.getOrInsertNamedMetadata("llvm.dbg.cu"));
EXPECT_TRUE(verifyModule(M));

ModulePassManager MPM(true);
MPM.addPass(VerifierPass(false));
ModuleAnalysisManager MAM(true);
MAM.registerPass(VerifierAnalysis());
MPM.run(M, &MAM);
EXPECT_FALSE(verifyModule(M));
}
}


Expand Down