[llvm] r281508 - Verifier: Mark orphaned DICompileUnits as a debug info failure.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 10:30:37 PDT 2016
Author: adrian
Date: Wed Sep 14 12:30:37 2016
New Revision: 281508
URL: http://llvm.org/viewvc/llvm-project?rev=281508&view=rev
Log:
Verifier: Mark orphaned DICompileUnits as a debug info failure.
This is a follow-up to r268778 that adds a couple of missing cases,
most notably orphaned compile units.
rdar://problem/28193346
Modified:
llvm/trunk/lib/IR/Verifier.cpp
llvm/trunk/unittests/IR/VerifierTest.cpp
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=281508&r1=281507&r2=281508&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Wed Sep 14 12:30:37 2016
@@ -2109,9 +2109,9 @@ void Verifier::visitFunction(const Funct
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);
}
}
@@ -4261,10 +4261,10 @@ void Verifier::visitDbgIntrinsic(StringR
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) {
@@ -4327,9 +4327,9 @@ void Verifier::verifyBitPieceExpression(
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() {
@@ -4337,7 +4337,7 @@ void Verifier::verifyCompileUnits() {
SmallPtrSet<const Metadata *, 2> Listed;
if (CUs)
Listed.insert(CUs->op_begin(), CUs->op_end());
- Assert(
+ AssertDI(
all_of(CUVisited,
[&Listed](const Metadata *CU) { return Listed.count(CU); }),
"All DICompileUnits must be listed in llvm.dbg.cu");
Modified: llvm/trunk/unittests/IR/VerifierTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/VerifierTest.cpp?rev=281508&r1=281507&r2=281508&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/VerifierTest.cpp (original)
+++ llvm/trunk/unittests/IR/VerifierTest.cpp Wed Sep 14 12:30:37 2016
@@ -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"
@@ -151,26 +152,58 @@ TEST(VerifierTest, InvalidFunctionLinkag
#ifndef _MSC_VER
// FIXME: This test causes an ICE in MSVC 2013.
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([&] { return 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([&] { return 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([&] { return VerifierAnalysis(); });
+ MPM.run(M, MAM);
+ EXPECT_FALSE(verifyModule(M));
+ }
}
#endif
More information about the llvm-commits
mailing list