Fix LLVM's use of DW_OP_bit_piece in DWARF expressions.
authorAdrian Prantl <aprantl@apple.com>
Fri, 9 Dec 2016 20:43:40 +0000 (20:43 +0000)
committerAdrian Prantl <aprantl@apple.com>
Fri, 9 Dec 2016 20:43:40 +0000 (20:43 +0000)
commit8fafb8d37861378bfc7432891edd8c75a3589f71
tree767b8dd7d993e271d72a45f9332b317f79a6ce20
parent34359cf0fa03ba36487390d7c2a98f6a014e3430
Fix LLVM's use of DW_OP_bit_piece in DWARF expressions.

LLVM's use of DW_OP_bit_piece is incorrect and a based on a
misunderstanding of the wording in the DWARF specification. The offset
argument of DW_OP_bit_piece refers to the offset into the location
that is on the top of the DWARF expression stack, and not an offset
into the source variable. This has since also been clarified in the
DWARF specification.

This patch fixes all uses of DW_OP_bit_piece to emit the correct
offset and simplifies the DwarfExpression class to semi-automaticaly
emit empty DW_OP_pieces to adjust the offset of the source variable,
thus simplifying the code using DwarfExpression.

While this is an incompatible bugfix, in practice I don't expect this
to be much of a problem since LLVM's old interpretation and the
correct interpretation of DW_OP_bit_piece differ only when there are
gaps in the fragmented locations of the described variables or if
individual fragments are smaller than a byte. LLDB at least won't
interpret locations with gaps in them because is has no way to present
undefined bits in a variable, and there is a high probability that an
old-form expression will be malformed when interpreted correctly,
because the DW_OP_bit_piece offset will be outside of the location at
the top of the stack.

As a nice side-effect, this patch enables us to use a more efficient
encoding for subregisters: In order to express a sub-register at a
non-zero offset we now use a DW_OP_bit_piece instead of shifting the
value into place manually.

This patch also adds missing test coverage for code paths that weren't
exercised before.

<rdar://problem/29335809>
Differential Revision: https://reviews.llvm.org/D27550

llvm-svn: 289266
15 files changed:
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/test/DebugInfo/AArch64/frameindices.ll
llvm/test/DebugInfo/MIR/ARM/lit.local.cfg [new file with mode: 0644]
llvm/test/DebugInfo/MIR/ARM/split-superreg-piece.mir [new file with mode: 0644]
llvm/test/DebugInfo/MIR/ARM/split-superreg.mir [new file with mode: 0644]
llvm/test/DebugInfo/MIR/X86/bit-piece-dh.mir [new file with mode: 0644]
llvm/test/DebugInfo/X86/PR26148.ll
llvm/test/DebugInfo/X86/dw_op_minus_direct.ll [new file with mode: 0644]