[llvm] b43235a - [DebugInfo] Fix DwarfExpression::addConstantFP for float on big-endian
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 02:49:05 PDT 2020
Author: Bjorn Pettersson
Date: 2020-08-20T11:48:05+02:00
New Revision: b43235a76c231cf15d28f073780e868b71c7bab0
URL: https://github.com/llvm/llvm-project/commit/b43235a76c231cf15d28f073780e868b71c7bab0
DIFF: https://github.com/llvm/llvm-project/commit/b43235a76c231cf15d28f073780e868b71c7bab0.diff
LOG: [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
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 4455035d8910..b0fa8645de24 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -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);
-
- const char *SwappedBytes = reinterpret_cast<const char *>(&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;
}
More information about the llvm-commits
mailing list