diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-01-21 00:59:20 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-01-21 00:59:20 +0000 |
commit | 34bcbeed03584aa9785df3b7c138341024c21257 (patch) | |
tree | a603302f274370f0e010a5b48fcb537cbf080e5c /llvm/lib/IR/DebugInfo.cpp | |
parent | 1efd55ff21eb3f9c2b94ddb7b97e316d0b926b64 (diff) | |
download | bcm5719-llvm-34bcbeed03584aa9785df3b7c138341024c21257.tar.gz bcm5719-llvm-34bcbeed03584aa9785df3b7c138341024c21257.zip |
Make DIExpression::Verify() stricter by checking that the number of
elements and the ordering is sane and cleanup the accessors.
llvm-svn: 226627
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 29 |
1 files changed, 24 insertions, 5 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; } |