Fix mac build pointer aliasing warnings
Now we cast to size_t before going to int32_t*, this removes the aliasing warning.
Change-Id: I696f509a4d64c036b434f353293eb3c97eee7c18
diff --git a/src/heap.cc b/src/heap.cc
index 3d84451..4576a90 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -497,8 +497,10 @@
DCHECK_GT(size, 0u);
COMPILE_ASSERT(sizeof(size_t) == sizeof(int32_t),
int32_t_must_be_same_size_as_size_t_for_used_atomic_operations);
- android_atomic_add(size, reinterpret_cast<volatile int32_t*>(&num_bytes_allocated_));
- android_atomic_add(1, reinterpret_cast<volatile int32_t*>(&num_objects_allocated_));
+ android_atomic_add(size, reinterpret_cast<volatile int32_t*>(
+ reinterpret_cast<size_t>(&num_bytes_allocated_)));
+ android_atomic_add(1, reinterpret_cast<volatile int32_t*>(
+ reinterpret_cast<size_t>(&num_objects_allocated_)));
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* global_stats = Runtime::Current()->GetStats();
@@ -525,11 +527,13 @@
int32_t_must_be_same_size_as_size_t_for_used_atomic_operations);
DCHECK_LE(freed_objects, num_objects_allocated_);
android_atomic_add(-static_cast<int32_t>(freed_objects),
- reinterpret_cast<volatile int32_t*>(&num_objects_allocated_));
+ reinterpret_cast<volatile int32_t*>(
+ reinterpret_cast<size_t>(&num_objects_allocated_)));
DCHECK_LE(freed_bytes, num_bytes_allocated_);
android_atomic_add(-static_cast<int32_t>(freed_bytes),
- reinterpret_cast<volatile int32_t*>(&num_bytes_allocated_));
+ reinterpret_cast<volatile int32_t*>(
+ reinterpret_cast<size_t>(&num_bytes_allocated_)));
if (Runtime::Current()->HasStatsEnabled()) {
RuntimeStats* global_stats = Runtime::Current()->GetStats();
diff --git a/src/mark_stack.h b/src/mark_stack.h
index dada4a5..224e6d4 100644
--- a/src/mark_stack.h
+++ b/src/mark_stack.h
@@ -48,7 +48,7 @@
DCHECK(obj != NULL);
DCHECK_NE(ptr_, limit_);
DCHECK_EQ(sizeof(ptr_), sizeof(int32_t));
- int32_t* ptr = reinterpret_cast<int32_t*>(&ptr_);
+ int32_t* ptr = reinterpret_cast<int32_t*>(reinterpret_cast<size_t>(&ptr_));
*reinterpret_cast<const Object**>(android_atomic_add(sizeof(*ptr_), ptr)) = obj;
}