Commit 23520d93 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][cleanup] Use {Read,Write}UnalignedValue

Minor cleanup: Instead of a cryptic memcpy, just use ReadUnalignedValue
and WriteUnalignedValue.
Also add DCHECKs to these helpers to ensure that they are only used for
trivially copyable types.

R=ahaas@chromium.org

Bug: v8:7310
Change-Id: Id5014a828573f8d13a6c3a5380eae2f377e8f130
Reviewed-on: https://chromium-review.googlesource.com/948544Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51740}
parent d4381010
......@@ -1579,6 +1579,7 @@ inline uintptr_t GetCurrentStackPosition() {
template <typename V>
static inline V ReadUnalignedValue(const void* p) {
ASSERT_TRIVIALLY_COPYABLE(V);
#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM)
return *reinterpret_cast<const V*>(p);
#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
......@@ -1590,6 +1591,7 @@ static inline V ReadUnalignedValue(const void* p) {
template <typename V>
static inline void WriteUnalignedValue(void* p, V value) {
ASSERT_TRIVIALLY_COPYABLE(V);
#if !(V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM)
*(reinterpret_cast<V*>(p)) = value;
#else // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_ARM
......
......@@ -11,6 +11,7 @@
#include "src/objects.h"
#include "src/snapshot/code-serializer.h"
#include "src/snapshot/serializer-common.h"
#include "src/utils.h"
#include "src/version.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder.h"
......@@ -35,7 +36,7 @@ class Writer {
os << "wrote: " << (size_t)value << " sized: " << sizeof(T) << std::endl;
}
DCHECK_GE(buffer_.size(), sizeof(T));
memcpy(buffer_.start(), reinterpret_cast<const byte*>(&value), sizeof(T));
WriteUnalignedValue(buffer_.start(), value);
buffer_ = buffer_ + sizeof(T);
}
......@@ -63,8 +64,7 @@ class Reader {
template <typename T>
T Read() {
DCHECK_GE(buffer_.size(), sizeof(T));
T ret;
memcpy(reinterpret_cast<byte*>(&ret), buffer_.start(), sizeof(T));
T ret = ReadUnalignedValue<T>(buffer_.start());
buffer_ = buffer_ + sizeof(T);
if (FLAG_wasm_trace_serialization) {
OFStream os(stdout);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment