d67f159332
TEST=local Change-Id: Icb47e2c68e55ae14f806cb421b8d860cda4d1f1c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350647 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
30 lines
861 B
C++
30 lines
861 B
C++
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_PLATFORM_UNALIGNED_H_
|
|
#define RUNTIME_PLATFORM_UNALIGNED_H_
|
|
|
|
#include "platform/globals.h"
|
|
#include "platform/undefined_behavior_sanitizer.h"
|
|
|
|
namespace dart {
|
|
|
|
template <typename T>
|
|
static inline T LoadUnaligned(const T* ptr) {
|
|
T value;
|
|
memcpy(reinterpret_cast<void*>(&value), // NOLINT
|
|
reinterpret_cast<const void*>(ptr), sizeof(value));
|
|
return value;
|
|
}
|
|
|
|
template <typename T>
|
|
static inline void StoreUnaligned(T* ptr, T value) {
|
|
memcpy(reinterpret_cast<void*>(ptr), // NOLINT
|
|
reinterpret_cast<const void*>(&value), sizeof(value));
|
|
}
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_PLATFORM_UNALIGNED_H_
|