1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[DebugInfo] Fix DwarfExpression::addConstantFP for float on big-endian

The byte swapping, when dealing with 4 byte (float) FP constants
in DwarfExpression::addConstantFP, added in commit ef8992b9f0189005
was not correct. It always performed byte swapping using an
uint64_t value. When dealing with 4 byte values the 4 interesting
bytes ended up in the big end of the uint64_t, but later we emitted
the 4 bytes at the little end. So we ended up with zeroes being
emitted and faulty debug information.

This patch simplifies things a bit, IMHO. Using the APInt
representation throughout the function, instead of looking at
the internal representation using getRawBytes and without using
reinterpret_cast etc. And using API.byteSwap() should result in
correct byte swapping independent of APInt being 4 or 8 bytes.

Differential Revision: https://reviews.llvm.org/D86272
This commit is contained in:
Bjorn Pettersson 2020-08-20 11:41:05 +02:00
parent 45c7e14aca
commit 1647429cc3

View File

@ -231,14 +231,16 @@ void DwarfExpression::addConstantFP(const APFloat &APF, const AsmPrinter &AP) {
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);
// 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();
const char *SwappedBytes = reinterpret_cast<const char *>(&Swapped);
for (int i = 0; i < NumBytes; ++i)
emitData1(SwappedBytes[i]);
for (int i = 0; i < NumBytes; ++i) {
emitData1(API.getZExtValue() & 0xFF);
API = API.lshr(8);
}
return;
}