Use 16 instead of 4 for determining member offsets.
authorrickyz <rickyz@chromium.org>
Tue, 18 Nov 2014 14:09:23 +0000 (06:09 -0800)
committerCommit bot <commit-bot@chromium.org>
Tue, 18 Nov 2014 14:09:34 +0000 (14:09 +0000)
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
src/heap/heap-inl.h

index 80a8949..371d7da 100644 (file)
@@ -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<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
+// Here we simply use the aligned, non-zero value 16.
+#define OFFSET_OF(type, field) \
+  (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(16)->field)) - 16)
 
 
 #if V8_OS_NACL
index 48e928d..549ecbc 100644 (file)
@@ -587,7 +587,7 @@ bool Heap::CollectGarbage(AllocationSpace space, const char* gc_reason,
 Isolate* Heap::isolate() {
   return reinterpret_cast<Isolate*>(
       reinterpret_cast<intptr_t>(this) -
-      reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4);
+      reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(16)->heap()) + 16);
 }