From 0d9f3f7f953e61534d7ba9e94ae579ac854fdeae Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 8 Feb 2019 01:43:23 +0000 Subject: [PATCH] [WebAssembly] Fixed Disassembler ignoring endian swap on big endian. Summary: This fixes: https://bugs.llvm.org/show_bug.cgi?id=40620 Reviewers: aheejin Subscribers: dschuff, sbc100, jgravelle-google, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57933 llvm-svn: 353496 --- .../WebAssembly/Disassembler/WebAssemblyDisassembler.cpp | 5 ++--- llvm/test/MC/Disassembler/WebAssembly/wasm.txt | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp index 2a0ccfc4737b..287b2443ddbd 100644 --- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp +++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp @@ -108,9 +108,8 @@ template bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef Bytes) { if (Size + sizeof(T) > Bytes.size()) return false; - T Val; - memcpy(&Val, Bytes.data() + Size, sizeof(T)); - support::endian::byte_swap(Val); + T Val = support::endian::read( + Bytes.data() + Size); Size += sizeof(T); if (std::is_floating_point::value) { MI.addOperand(MCOperand::createFPImm(static_cast(Val))); diff --git a/llvm/test/MC/Disassembler/WebAssembly/wasm.txt b/llvm/test/MC/Disassembler/WebAssembly/wasm.txt index 8e4607de6d53..8a119fb6b0f4 100644 --- a/llvm/test/MC/Disassembler/WebAssembly/wasm.txt +++ b/llvm/test/MC/Disassembler/WebAssembly/wasm.txt @@ -33,9 +33,7 @@ # CHECK: i64.trunc_sat_f64_u 0xFC 0x07 -# FIXME Disabled temporarily due to failures in clang-ppc64be-linux and -# clang-s390x-linux bots -# C HECK: v128.const 50462976, 117835012, 185207048, 252579084 +# CHECK: v128.const 50462976, 117835012, 185207048, 252579084 0xFD 0x02 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F # CHECK: v8x16.shuffle 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15