From 64a96f5a7e2b64131115909cc9854459ed97c3b4 Mon Sep 17 00:00:00 2001 From: rickyz Date: Tue, 18 Nov 2014 06:09:23 -0800 Subject: [PATCH] Use 16 instead of 4 for determining member offsets. This avoids UBSan warnings about unaligned memory access. BUG= Review URL: https://codereview.chromium.org/734873002 Cr-Commit-Position: refs/heads/master@{#25396} --- src/base/macros.h | 6 +++--- src/heap/heap-inl.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/macros.h b/src/base/macros.h index 80a89496a..371d7da6e 100644 --- a/src/base/macros.h +++ b/src/base/macros.h @@ -20,9 +20,9 @@ // corresponds to 'offsetof' (in stddef.h), except that it doesn't // use 0 or NULL, which causes a problem with the compiler warnings // we have enabled (which is also why 'offsetof' doesn't seem to work). -// Here we simply use the non-zero value 4, which seems to work. -#define OFFSET_OF(type, field) \ - (reinterpret_cast(&(reinterpret_cast(4)->field)) - 4) +// Here we simply use the aligned, non-zero value 16. +#define OFFSET_OF(type, field) \ + (reinterpret_cast(&(reinterpret_cast(16)->field)) - 16) #if V8_OS_NACL diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index 48e928d71..549ecbc9a 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -587,7 +587,7 @@ bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason, Isolate* Heap::isolate() { return reinterpret_cast( reinterpret_cast(this) - - reinterpret_cast(reinterpret_cast(4)->heap()) + 4); + reinterpret_cast(reinterpret_cast(16)->heap()) + 16); } -- 2.34.1