From 4c9121d5d95194308bed09ec3d5c3611c4e9eac7 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Tue, 17 Feb 2015 22:30:56 +0000 Subject: [PATCH] AsmPrinter: Take range in DwarfExpression::AddExpression(), NFC Previously `DwarfExpression::AddExpression()` relied on default-constructing the end iterators for `DIExpression` -- once the operands are represented explicitly via `MDExpression` (instead of via the strange `StringRef` navigator in `DIHeaderIterator`) this won't work. Explicitly take an iterator for the end of the range. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229572 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 7 +++++-- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 2 +- lib/CodeGen/AsmPrinter/DwarfExpression.cpp | 5 +++-- lib/CodeGen/AsmPrinter/DwarfExpression.h | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 81f2329657b..a620ebba241 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -527,8 +527,11 @@ DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV, const TargetFrameLowering *TFI = Asm->TM.getSubtargetImpl()->getFrameLowering(); int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); + assert(Expr != DV.getExpression().end() && + "Wrong number of expressions"); DwarfExpr.AddMachineRegIndirect(FrameReg, Offset); - DwarfExpr.AddExpression(*(Expr++)); + DwarfExpr.AddExpression(Expr->begin(), Expr->end()); + ++Expr; } addBlock(*VariableDie, dwarf::DW_AT_location, Loc); @@ -780,7 +783,7 @@ void DwarfCompileUnit::addComplexAddress(const DbgVariable &DV, DIE &Die, ValidReg = DwarfExpr.AddMachineRegIndirect(Location.getReg(), Location.getOffset()); if (ValidReg) - DwarfExpr.AddExpression(Expr); + DwarfExpr.AddExpression(Expr.begin(), Expr.end()); } else ValidReg = DwarfExpr.AddMachineRegExpression(Expr, Location.getReg()); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index e214591a1fd..4aa12ed2506 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1725,7 +1725,7 @@ void DwarfDebug::emitDebugLocValue(ByteStreamer &Streamer, // Complex address entry. if (Loc.getOffset()) { DwarfExpr.AddMachineRegIndirect(Loc.getReg(), Loc.getOffset()); - DwarfExpr.AddExpression(Expr, PieceOffsetInBits); + DwarfExpr.AddExpression(Expr.begin(), Expr.end(), PieceOffsetInBits); } else DwarfExpr.AddMachineRegExpression(Expr, Loc.getReg(), PieceOffsetInBits); diff --git a/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/lib/CodeGen/AsmPrinter/DwarfExpression.cpp index 3d1e3822c51..fcab067424e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -240,13 +240,14 @@ bool DwarfExpression::AddMachineRegExpression(DIExpression Expr, return false; // Emit remaining elements of the expression. - AddExpression(I, PieceOffsetInBits); + AddExpression(I, Expr.end(), PieceOffsetInBits); return true; } void DwarfExpression::AddExpression(DIExpression::iterator I, + DIExpression::iterator E, unsigned PieceOffsetInBits) { - for (; I != DIExpression::iterator(); ++I) { + for (; I != E; ++I) { switch (*I) { case dwarf::DW_OP_bit_piece: { unsigned OffsetInBits = I->getArg(1); diff --git a/lib/CodeGen/AsmPrinter/DwarfExpression.h b/lib/CodeGen/AsmPrinter/DwarfExpression.h index d4062e8e3bc..b90b7b682ac 100644 --- a/lib/CodeGen/AsmPrinter/DwarfExpression.h +++ b/lib/CodeGen/AsmPrinter/DwarfExpression.h @@ -96,7 +96,8 @@ public: /// Emit a the operations remaining the DIExpressionIterator I. /// \param PieceOffsetInBits If this is one piece out of a fragmented /// location, this is the offset of the piece inside the entire variable. - void AddExpression(DIExpression::iterator I, unsigned PieceOffsetInBits = 0); + void AddExpression(DIExpression::iterator I, DIExpression::iterator E, + unsigned PieceOffsetInBits = 0); }; /// DwarfExpression implementation for .debug_loc entries. -- 2.34.1