diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -231,14 +231,16 @@ emitOp(dwarf::DW_OP_implicit_value); emitUnsigned(NumBytes /*Size of the block in bytes*/); - const uint64_t *Value = API.getRawData(); - const bool IsLittleEndian = AP.getDataLayout().isLittleEndian(); - uint64_t Swapped = support::endian::byte_swap( - *Value, IsLittleEndian ? support::little : support::big); - - const char *SwappedBytes = reinterpret_cast(&Swapped); - for (int i = 0; i < NumBytes; ++i) - emitData1(SwappedBytes[i]); + // The loop below is emitting the value starting at least significant byte, + // so we need to perform a byte-swap to get the byte order correct in case + // of a big-endian target. + if (AP.getDataLayout().isBigEndian()) + API = API.byteSwap(); + + for (int i = 0; i < NumBytes; ++i) { + emitData1(API.getZExtValue() & 0xFF); + API = API.lshr(8); + } return; }