[PATCH] D67926: Fix endianness handling in AVR MC
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 22:17:57 PDT 2019
serge-sans-paille updated this revision to Diff 221462.
serge-sans-paille edited the summary of this revision.
serge-sans-paille added a comment.
Remove reinterpret_cast as suggested by @efriedma
Force conversion native -> little
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67926/new/
https://reviews.llvm.org/D67926
Files:
llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
Index: llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
===================================================================
--- llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
+++ llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp
@@ -26,6 +26,7 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/EndianStream.h"
#define DEBUG_TYPE "mccodeemitter"
@@ -268,14 +269,11 @@
void AVRMCCodeEmitter::emitInstruction(uint64_t Val, unsigned Size,
const MCSubtargetInfo &STI,
raw_ostream &OS) const {
- const uint16_t *Words = reinterpret_cast<uint16_t const *>(&Val);
size_t WordCount = Size / 2;
for (int64_t i = WordCount - 1; i >= 0; --i) {
- uint16_t Word = Words[i];
-
- OS << (uint8_t) ((Word & 0x00ff) >> 0);
- OS << (uint8_t) ((Word & 0xff00) >> 8);
+ uint16_t Word = (Val >> i * 16) & 0xFFFF;
+ support::endian::write(OS, Word, support::endianness::little);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67926.221462.patch
Type: text/x-patch
Size: 1080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190924/668733e1/attachment.bin>
More information about the llvm-commits
mailing list