diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 29 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 16 |
2 files changed, 36 insertions, 9 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 9003fff7071..5dff50d362f 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -148,17 +148,18 @@ uint64_t DIExpression::getElement(unsigned Idx) const { } bool DIExpression::isVariablePiece() const { - return getNumElements() && getElement(0) == dwarf::DW_OP_piece; + unsigned N = getNumElements(); + return N >=3 && getElement(N-3) == dwarf::DW_OP_piece; } uint64_t DIExpression::getPieceOffset() const { - assert(isVariablePiece()); - return getElement(1); + assert(isVariablePiece() && "not a piece"); + return getElement(getNumElements()-2); } uint64_t DIExpression::getPieceSize() const { - assert(isVariablePiece()); - return getElement(2); + assert(isVariablePiece() && "not a piece"); + return getElement(getNumElements()-1); } //===----------------------------------------------------------------------===// @@ -593,6 +594,24 @@ bool DIExpression::Verify() const { if (!DbgNode) return true; + unsigned N = getNumElements(); + for (unsigned I = 0; I < N; ++I) + switch (getElement(I)) { + case DW_OP_piece: + // DW_OP_piece has to be the last element in the expression and take two + // arguments. + if (getElement(I) == DW_OP_piece && !isVariablePiece()) + return false; + I += 2; + break; + case DW_OP_plus: + // Takes one argument. + if (I+1 == N) + return false; + I += 1; + break; + default: break; + } return isExpression() && DbgNode->getNumOperands() == 1; } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index c95018d1772..8a523c28016 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2841,12 +2841,20 @@ void DebugInfoVerifier::processCallInst(DebugInfoFinder &Finder, if (Function *F = CI.getCalledFunction()) if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) switch (ID) { - case Intrinsic::dbg_declare: - Finder.processDeclare(*M, cast<DbgDeclareInst>(&CI)); + case Intrinsic::dbg_declare: { + auto *DDI = cast<DbgDeclareInst>(&CI); + Finder.processDeclare(*M, DDI); + if (auto E = DDI->getExpression()) + Assert1(DIExpression(E).Verify(), "DIExpression does not Verify!", E); break; - case Intrinsic::dbg_value: - Finder.processValue(*M, cast<DbgValueInst>(&CI)); + } + case Intrinsic::dbg_value: { + auto *DVI = cast<DbgValueInst>(&CI); + Finder.processValue(*M, DVI); + if (auto E = DVI->getExpression()) + Assert1(DIExpression(E).Verify(), "DIExpression does not Verify!", E); break; + } default: break; } |