Reviewers: jochen (slow),

Message:
Hey, I've been looking at ubsan warnings in chrome, and taking a stab at fixing
some of the low hanging fruit. This shouldn't make any difference in the
generated code, but might as well clean up some of the noise in the ubsan
output.

Description:
Use 16 instead of 4 for determining member offsets.

This avoids UBSan warnings about unaligned memory access.

BUG=

Please review this at https://codereview.chromium.org/734873002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+4, -4 lines):
  M src/base/macros.h
  M src/heap/heap-inl.h


Index: src/base/macros.h
diff --git a/src/base/macros.h b/src/base/macros.h
index 80a89496a5e25bc06caf3aa6445cdbb11b484303..371d7da6eaa72251a9693096f64a79def1b8fa49 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<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: src/heap/heap-inl.h
diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h
index 48e928d71106c1f7785b04d4cc7eebb8bd1b3de8..549ecbc9a64eafe8f93c77c67e7e90d1f6a9afe2 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<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);
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to