Reviewers: Mads Ager, vegorov,

Message:
Guys,

may you have a look?

Description:
Using unsigned shifts and masks when dealing with 64-bit addresses.

BUG=v8:1037

Please review this at http://codereview.chromium.org/6242005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M include/v8.h
  M src/api.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 7d18107d92d228c8f6de6e6d519d524e0f5de8ce..641837b72282fc4ea4f65cce2b3c52fd9054f839 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3367,7 +3367,7 @@ template <> struct SmiTagging<4> {

   // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
   // with a plain reinterpret_cast.
-  static const intptr_t kEncodablePointerMask = 0x1;
+  static const uintptr_t kEncodablePointerMask = 0x1;
   static const int kPointerToSmiShift = 0;
 };

@@ -3387,7 +3387,7 @@ template <> struct SmiTagging<8> {
// It might be not enough to cover stack allocated objects on some platforms.
   static const int kPointerAlignment = 3;

-  static const intptr_t kEncodablePointerMask =
+  static const uintptr_t kEncodablePointerMask =
       ~(intptr_t(0xffffffff) << kPointerAlignment);

   static const int kPointerToSmiShift =
@@ -3397,7 +3397,7 @@ template <> struct SmiTagging<8> {
 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
-const intptr_t kEncodablePointerMask =
+const uintptr_t kEncodablePointerMask =
     PlatformSmiTagging::kEncodablePointerMask;
 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;

@@ -3457,7 +3457,7 @@ class Internals {
   }

   static inline void* GetExternalPointerFromSmi(internal::Object* value) {
-    const intptr_t address = reinterpret_cast<intptr_t>(value);
+    const uintptr_t address = reinterpret_cast<intptr_t>(value);
     return reinterpret_cast<void*>(address >> kPointerToSmiShift);
   }

Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 073306f071a2a260029750d82317014e0067f84f..dbd93b8d5c2c7380b1aefb2cc4560b1bfedce8ab 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3267,14 +3267,14 @@ void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {


 static bool CanBeEncodedAsSmi(void* ptr) {
-  const intptr_t address = reinterpret_cast<intptr_t>(ptr);
+  const uintptr_t address = reinterpret_cast<intptr_t>(ptr);
   return ((address & i::kEncodablePointerMask) == 0);
 }


 static i::Smi* EncodeAsSmi(void* ptr) {
   ASSERT(CanBeEncodedAsSmi(ptr));
-  const intptr_t address = reinterpret_cast<intptr_t>(ptr);
+  const uintptr_t address = reinterpret_cast<intptr_t>(ptr);
i::Smi* result = reinterpret_cast<i::Smi*>(address << i::kPointerToSmiShift);
   ASSERT(i::Internals::HasSmiTag(result));
   ASSERT_EQ(result, i::Smi::FromInt(result->value()));
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 6a2f3289f8941ed1993f922207a3ecb96546232f..fc2c5e548232328b8106ac98b96e47bca94a7a53 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -874,6 +874,10 @@ THREADED_TEST(ExternalWrap) {
   TestExternalPointerWrapping();

 #if defined(V8_HOST_ARCH_X64)
+  // Check a value with a leading 1 bit in x64 Smi encoding.
+  expected_ptr = reinterpret_cast<void*>(0x400000000);
+  TestExternalPointerWrapping();
+
   expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
   TestExternalPointerWrapping();



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to