From a475da36eb5013143c19074e3edfc8977ed15b2a Mon Sep 17 00:00:00 2001 From: Markus Lavin Date: Tue, 30 Apr 2019 07:58:57 +0000 Subject: [DebugInfo] DW_OP_deref_size in PrologEpilogInserter. The PrologEpilogInserter need to insert a DW_OP_deref_size before prepending a memory location expression to an already implicit expression to avoid having the existing expression act on the memory address instead of the value behind it. The reason for using DW_OP_deref_size and not plain DW_OP_deref is that big-endian targets need to read the right size as simply truncating a larger read would yield the wrong result (LSB bytes are not at the lower address). This re-commit fixes issues reported in the first one. Namely deref was inserted under wrong conditions and additionally the deref_size argument was incorrectly encoded. Differential Revision: https://reviews.llvm.org/D59687 llvm-svn: 359535 --- llvm/lib/CodeGen/PrologEpilogInserter.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp') diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 67834c8c352..55925c8cf45 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -1172,12 +1172,26 @@ void PEI::replaceFrameIndices(MachineBasicBlock *BB, MachineFunction &MF, assert(i == 0 && "Frame indices can only appear as the first " "operand of a DBG_VALUE machine instruction"); unsigned Reg; + unsigned FrameIdx = MI.getOperand(0).getIndex(); + unsigned Size = MF.getFrameInfo().getObjectSize(FrameIdx); + int64_t Offset = - TFI->getFrameIndexReference(MF, MI.getOperand(0).getIndex(), Reg); + TFI->getFrameIndexReference(MF, FrameIdx, Reg); MI.getOperand(0).ChangeToRegister(Reg, false /*isDef*/); MI.getOperand(0).setIsDebug(); - auto *DIExpr = DIExpression::prepend(MI.getDebugExpression(), - DIExpression::NoDeref, Offset); + + const DIExpression *DIExpr = MI.getDebugExpression(); + // If we have DBG_VALUE that is indirect and has a Implicit location + // expression need to insert a deref before prepending a Memory + // location expression. Also after doing this we change the DBG_VALUE + // to be direct. + if (MI.isIndirectDebugValue() && DIExpr->isImplicit()) { + SmallVector Ops = {dwarf::DW_OP_deref_size, Size}; + DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, DIExpression::WithStackValue); + // Make the DBG_VALUE direct. + MI.getOperand(1).ChangeToRegister(0, false); + } + DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset); MI.getOperand(3).setMetadata(DIExpr); continue; } -- cgit v1.2.3