[PATCH] D86272: [DebugInfo] Fix DwarfExpression::addConstantFP for float on big-endian
Bjorn Pettersson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 02:43:25 PDT 2020
bjope created this revision.
bjope added reviewers: SouraVX, aprantl.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
bjope requested review of this revision.
The byte swapping, when dealing with 4 byte (float) FP constants
in DwarfExpression::addConstantFP, added in commit ef8992b9f0189005 <https://reviews.llvm.org/rGef8992b9f0189005e0d9e09bd0967301bd7a7cc6>
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86272
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ 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<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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86272.286752.patch
Type: text/x-patch
Size: 1147 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200820/ddf850a4/attachment-0001.bin>
More information about the llvm-commits
mailing list