[libcxxabi] r228904 - unwind: use explicit memcpy for register saving
Saleem Abdulrasool
compnerd at compnerd.org
Wed Feb 11 20:25:06 PST 2015
Author: compnerd
Date: Wed Feb 11 22:25:05 2015
New Revision: 228904
URL: http://llvm.org/viewvc/llvm-project?rev=228904&view=rev
Log:
unwind: use explicit memcpy for register saving
Convert the register saving code to use an explicit memcpy rather than the
implicit memcpy from the assignment. This avoids warnings from -Wcast-qual on
GCC and makes the code more explicit. Furthermore, use sizeof to calculate the
offsets rather than adding magic numbers, improving legibility of the code.
NFC.
Modified:
libcxxabi/trunk/src/Unwind/Registers.hpp
Modified: libcxxabi/trunk/src/Unwind/Registers.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/Unwind/Registers.hpp?rev=228904&r1=228903&r2=228904&view=diff
==============================================================================
--- libcxxabi/trunk/src/Unwind/Registers.hpp (original)
+++ libcxxabi/trunk/src/Unwind/Registers.hpp Wed Feb 11 22:25:05 2015
@@ -89,7 +89,7 @@ private:
inline Registers_x86::Registers_x86(const void *registers) {
static_assert(sizeof(Registers_x86) < sizeof(unw_context_t),
"x86 registers do not fit into unw_context_t");
- _registers = *((GPRs *)registers);
+ memcpy(&_registers, registers, sizeof(_registers));
}
inline Registers_x86::Registers_x86() {
@@ -281,7 +281,7 @@ private:
inline Registers_x86_64::Registers_x86_64(const void *registers) {
static_assert(sizeof(Registers_x86_64) < sizeof(unw_context_t),
"x86_64 registers do not fit into unw_context_t");
- _registers = *((GPRs *)registers);
+ memcpy(&_registers, registers, sizeof(_registers));
}
inline Registers_x86_64::Registers_x86_64() {
@@ -546,9 +546,19 @@ private:
inline Registers_ppc::Registers_ppc(const void *registers) {
static_assert(sizeof(Registers_ppc) < sizeof(unw_context_t),
"ppc registers do not fit into unw_context_t");
- _registers = *((ppc_thread_state_t *)registers);
- _floatRegisters = *((ppc_float_state_t *)((char *)registers + 160));
- memcpy(_vectorRegisters, ((char *)registers + 424), sizeof(_vectorRegisters));
+ memcpy(&_registers, static_cast<const uint8_t *>(registers),
+ sizeof(_registers));
+ static_assert(sizeof(ppc_thread_state_t) == 160,
+ "expected float register offset to be 160");
+ memcpy(&_floatRegisters,
+ static_cast<const uint8_t *>(registers) + sizeof(ppc_thread_state_t),
+ sizeof(_floatRegisters));
+ static_assert(sizeof(ppc_thread_state_t) + sizeof(ppc_float_state_t) == 424,
+ "expected vector register offset to be 424 bytes");
+ memcpy(_vectorRegisters,
+ static_cast<const uint8_t *>(registers) + sizeof(ppc_thread_state_t) +
+ sizeof(ppc_float_state_t),
+ sizeof(_vectorRegisters));
}
inline Registers_ppc::Registers_ppc() {
@@ -1065,7 +1075,10 @@ inline Registers_arm64::Registers_arm64(
static_assert(sizeof(Registers_arm64) < sizeof(unw_context_t),
"arm64 registers do not fit into unw_context_t");
memcpy(&_registers, registers, sizeof(_registers));
- memcpy(_vectorHalfRegisters, (((char *)registers) + 0x110),
+ static_assert(sizeof(GPRs) == 0x110,
+ "expected VFP registers to be at offset 272");
+ memcpy(_vectorHalfRegisters,
+ static_cast<const uint8_t *>(registers) + sizeof(GPRs),
sizeof(_vectorHalfRegisters));
}
More information about the cfe-commits
mailing list