[clang] Use -Wshorten-64-to-32 to enable warnings about 64bit to 32bit truncations.
authorbmeurer <bmeurer@chromium.org>
Tue, 28 Apr 2015 06:54:08 +0000 (23:54 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 28 Apr 2015 06:53:41 +0000 (06:53 +0000)
Currently only the Win64 bots report this warnings, which adds quite
some overhead to the development process. With this flag we also get
compiler warnings about implicit 64bit to 32bit truncations when
building with clang on Linux/x64 and Mac/x64.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/1111733002

Cr-Commit-Position: refs/heads/master@{#28093}

24 files changed:
build/standalone.gypi
samples/process.cc
samples/shell.cc
src/base/platform/platform-aix.cc
src/base/platform/platform-cygwin.cc
src/base/platform/platform-freebsd.cc
src/base/platform/platform-linux.cc
src/base/platform/platform-macos.cc
src/base/platform/platform-openbsd.cc
src/base/platform/platform-posix.cc
src/base/platform/platform-qnx.cc
src/base/platform/platform-solaris.cc
src/base/platform/platform-win32.cc
src/base/platform/platform.h
src/base/platform/time.cc
src/d8-posix.cc
src/d8.cc
src/flags.cc
src/gdb-jit.cc
src/snapshot/mksnapshot.cc
src/utils.cc
test/cctest/compiler/call-tester.h
test/cctest/test-mark-compact.cc
tools/shell-utils.h

index cd7847b..7c96720 100644 (file)
               '-Wall',
               '-Werror',
               '-Wextra',
+              '-Wshorten-64-to-32',
             ],
             'cflags+': [
               # Clang considers the `register` keyword as deprecated, but
         'cflags_cc': [ '-Wnon-virtual-dtor', '-fno-rtti', '-std=gnu++0x' ],
         'ldflags': [ '-pthread', ],
         'conditions': [
+          # TODO(arm64): It'd be nice to enable this for arm64 as well,
+          # but the Assembler requires some serious fixing first.
+          [ 'clang==1 and v8_target_arch=="x64"', {
+            'cflags': [ '-Wshorten-64-to-32' ],
+          }],
           [ 'host_arch=="ppc64" and OS!="aix"', {
             'cflags': [ '-mminimal-toc' ],
           }],
index f447970..e0c273e 100644 (file)
@@ -595,18 +595,21 @@ Handle<String> ReadFile(Isolate* isolate, const string& name) {
   if (file == NULL) return Handle<String>();
 
   fseek(file, 0, SEEK_END);
-  int size = ftell(file);
+  size_t size = ftell(file);
   rewind(file);
 
   char* chars = new char[size + 1];
   chars[size] = '\0';
-  for (int i = 0; i < size;) {
-    int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
-    i += read;
+  for (size_t i = 0; i < size;) {
+    i += fread(&chars[i], 1, size - i, file);
+    if (ferror(file)) {
+      fclose(file);
+      return Handle<String>();
+    }
   }
   fclose(file);
-  Handle<String> result =
-      String::NewFromUtf8(isolate, chars, String::kNormalString, size);
+  Handle<String> result = String::NewFromUtf8(
+      isolate, chars, String::kNormalString, static_cast<int>(size));
   delete[] chars;
   return result;
 }
index 0ed742d..a061aa4 100644 (file)
@@ -238,18 +238,21 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
   if (file == NULL) return v8::Handle<v8::String>();
 
   fseek(file, 0, SEEK_END);
-  int size = ftell(file);
+  size_t size = ftell(file);
   rewind(file);
 
   char* chars = new char[size + 1];
   chars[size] = '\0';
-  for (int i = 0; i < size;) {
-    int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
-    i += read;
+  for (size_t i = 0; i < size;) {
+    i += fread(&chars[i], 1, size - i, file);
+    if (ferror(file)) {
+      fclose(file);
+      return v8::Handle<v8::String>();
+    }
   }
   fclose(file);
-  v8::Handle<v8::String> result =
-      v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
+  v8::Handle<v8::String> result = v8::String::NewFromUtf8(
+      isolate, chars, v8::String::kNormalString, static_cast<int>(size));
   delete[] chars;
   return result;
 }
index 3083f75..513f5c8 100644 (file)
@@ -73,55 +73,6 @@ void* OS::Allocate(const size_t requested, size_t* allocated, bool executable) {
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-      : file_(file), memory_(memory), size_(size) {}
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
-
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-                                                   void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) munmap(memory_, size_);
-  fclose(file_);
-}
-
-
 static unsigned StringToLong(char* buffer) {
   return static_cast<unsigned>(strtol(buffer, NULL, 16));  // NOLINT
 }
index 8a767cf..e09fc68 100644 (file)
@@ -59,54 +59,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) munmap(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   std::vector<SharedLibraryAddresses> result;
   // This function assumes that the layout of the file is as follows:
index 68ed70a..8fe908c 100644 (file)
@@ -68,54 +68,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) munmap(memory_, size_);
-  fclose(file_);
-}
-
-
 static unsigned StringToLong(char* buffer) {
   return static_cast<unsigned>(strtol(buffer, NULL, 16));  // NOLINT
 }
index 36857e6..874c6db 100644 (file)
@@ -142,64 +142,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-           size,
-           PROT_READ | PROT_WRITE,
-           MAP_SHARED,
-           fileno(file),
-           0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-           size,
-           PROT_READ | PROT_WRITE,
-           MAP_SHARED,
-           fileno(file),
-           0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) OS::Free(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   std::vector<SharedLibraryAddress> result;
   // This function assumes that the layout of the file is as follows:
@@ -271,7 +213,7 @@ void OS::SignalCodeMovingGC() {
   // it. This injects a GC marker into the stream of events generated
   // by the kernel and allows us to synchronize V8 code log and the
   // kernel log.
-  int size = sysconf(_SC_PAGESIZE);
+  long size = sysconf(_SC_PAGESIZE);  // NOLINT(runtime/int)
   FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
   if (f == NULL) {
     OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
@@ -286,7 +228,7 @@ void OS::SignalCodeMovingGC() {
                     PROT_READ | PROT_EXEC,
 #endif
                     MAP_PRIVATE, fileno(f), 0);
-  DCHECK(addr != MAP_FAILED);
+  DCHECK_NE(MAP_FAILED, addr);
   OS::Free(addr, size);
   fclose(f);
 }
index 77893ee..4b760c3 100644 (file)
@@ -68,64 +68,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-           size,
-           PROT_READ | PROT_WRITE,
-           MAP_SHARED,
-           fileno(file),
-           0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-          size,
-          PROT_READ | PROT_WRITE,
-          MAP_SHARED,
-          fileno(file),
-          0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) OS::Free(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   std::vector<SharedLibraryAddress> result;
   unsigned int images_count = _dyld_image_count();
index 4e706cb..32b1af1 100644 (file)
@@ -66,54 +66,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) OS::Free(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   std::vector<SharedLibraryAddress> result;
   // This function assumes that the layout of the file is as follows:
index e43493f..8fb40b0 100644 (file)
@@ -259,6 +259,65 @@ void OS::DebugBreak() {
 }
 
 
+class PosixMemoryMappedFile final : public OS::MemoryMappedFile {
+ public:
+  PosixMemoryMappedFile(FILE* file, void* memory, size_t size)
+      : file_(file), memory_(memory), size_(size) {}
+  ~PosixMemoryMappedFile() final;
+  void* memory() const final { return memory_; }
+  size_t size() const final { return size_; }
+
+ private:
+  FILE* const file_;
+  void* const memory_;
+  size_t const size_;
+};
+
+
+// static
+OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
+  if (FILE* file = fopen(name, "r+")) {
+    if (fseek(file, 0, SEEK_END) == 0) {
+      long size = ftell(file);  // NOLINT(runtime/int)
+      if (size >= 0) {
+        void* const memory =
+            mmap(OS::GetRandomMmapAddr(), size, PROT_READ | PROT_WRITE,
+                 MAP_SHARED, fileno(file), 0);
+        if (memory != MAP_FAILED) {
+          return new PosixMemoryMappedFile(file, memory, size);
+        }
+      }
+    }
+    fclose(file);
+  }
+  return nullptr;
+}
+
+
+// static
+OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
+                                                   size_t size, void* initial) {
+  if (FILE* file = fopen(name, "w+")) {
+    size_t result = fwrite(initial, 1, size, file);
+    if (result == size && !ferror(file)) {
+      void* memory = mmap(OS::GetRandomMmapAddr(), result,
+                          PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
+      if (memory != MAP_FAILED) {
+        return new PosixMemoryMappedFile(file, memory, result);
+      }
+    }
+    fclose(file);
+  }
+  return nullptr;
+}
+
+
+PosixMemoryMappedFile::~PosixMemoryMappedFile() {
+  if (memory_) OS::Free(memory_, size_);
+  fclose(file_);
+}
+
+
 int OS::GetCurrentProcessId() {
   return static_cast<int>(getpid());
 }
@@ -285,7 +344,7 @@ int OS::GetCurrentThreadId() {
 // POSIX date/time support.
 //
 
-int OS::GetUserTime(uint32_t* secs,  uint32_t* usecs) {
+int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
 #if V8_OS_NACL
   // Optionally used in Logger::ResourceEvent.
   return -1;
@@ -293,8 +352,8 @@ int OS::GetUserTime(uint32_t* secs,  uint32_t* usecs) {
   struct rusage usage;
 
   if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
-  *secs = usage.ru_utime.tv_sec;
-  *usecs = usage.ru_utime.tv_usec;
+  *secs = static_cast<uint32_t>(usage.ru_utime.tv_sec);
+  *usecs = static_cast<uint32_t>(usage.ru_utime.tv_usec);
   return 0;
 #endif
 }
index 2cb3228..9f22db5 100644 (file)
@@ -117,64 +117,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-           size,
-           PROT_READ | PROT_WRITE,
-           MAP_SHARED,
-           fileno(file),
-           0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(OS::GetRandomMmapAddr(),
-           size,
-           PROT_READ | PROT_WRITE,
-           MAP_SHARED,
-           fileno(file),
-           0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) OS::Free(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   std::vector<SharedLibraryAddress> result;
   procfs_mapinfo *mapinfos = NULL, *mapinfo;
index b9a2ec8..e844aa1 100644 (file)
@@ -63,54 +63,6 @@ void* OS::Allocate(const size_t requested,
 }
 
 
-class PosixMemoryMappedFile : public OS::MemoryMappedFile {
- public:
-  PosixMemoryMappedFile(FILE* file, void* memory, int size)
-    : file_(file), memory_(memory), size_(size) { }
-  virtual ~PosixMemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
- private:
-  FILE* file_;
-  void* memory_;
-  int size_;
-};
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
-  FILE* file = fopen(name, "r+");
-  if (file == NULL) return NULL;
-
-  fseek(file, 0, SEEK_END);
-  int size = ftell(file);
-
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
-  FILE* file = fopen(name, "w+");
-  if (file == NULL) return NULL;
-  int result = fwrite(initial, size, 1, file);
-  if (result < 1) {
-    fclose(file);
-    return NULL;
-  }
-  void* memory =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
-  return new PosixMemoryMappedFile(file, memory, size);
-}
-
-
-PosixMemoryMappedFile::~PosixMemoryMappedFile() {
-  if (memory_) munmap(memory_, size_);
-  fclose(file_);
-}
-
-
 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
   return std::vector<SharedLibraryAddress>();
 }
index 4328039..b0677af 100644 (file)
@@ -838,38 +838,38 @@ void OS::DebugBreak() {
 }
 
 
-class Win32MemoryMappedFile : public OS::MemoryMappedFile {
+class Win32MemoryMappedFile final : public OS::MemoryMappedFile {
  public:
-  Win32MemoryMappedFile(HANDLE file,
-                        HANDLE file_mapping,
-                        void* memory,
-                        int size)
+  Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory,
+                        size_t size)
       : file_(file),
         file_mapping_(file_mapping),
         memory_(memory),
-        size_(size) { }
-  virtual ~Win32MemoryMappedFile();
-  virtual void* memory() { return memory_; }
-  virtual int size() { return size_; }
+        size_(size) {}
+  ~Win32MemoryMappedFile() final;
+  void* memory() const final { return memory_; }
+  size_t size() const final { return size_; }
+
  private:
-  HANDLE file_;
-  HANDLE file_mapping_;
-  void* memory_;
-  int size_;
+  HANDLE const file_;
+  HANDLE const file_mapping_;
+  void* const memory_;
+  size_t const size_;
 };
 
 
+// static
 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
   // Open a physical file
   HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
       FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
   if (file == INVALID_HANDLE_VALUE) return NULL;
 
-  int size = static_cast<int>(GetFileSize(file, NULL));
+  DWORD size = GetFileSize(file, NULL);
 
   // Create a file mapping for the physical file
-  HANDLE file_mapping = CreateFileMapping(file, NULL,
-      PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
+  HANDLE file_mapping =
+      CreateFileMapping(file, NULL, PAGE_READWRITE, 0, size, NULL);
   if (file_mapping == NULL) return NULL;
 
   // Map a view of the file into memory
@@ -878,15 +878,17 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
 }
 
 
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
-    void* initial) {
+// static
+OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
+                                                   size_t size, void* initial) {
   // Open a physical file
   HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
-      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
+                            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+                            OPEN_ALWAYS, 0, NULL);
   if (file == NULL) return NULL;
   // Create a file mapping for the physical file
-  HANDLE file_mapping = CreateFileMapping(file, NULL,
-      PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
+  HANDLE file_mapping = CreateFileMapping(file, NULL, PAGE_READWRITE, 0,
+                                          static_cast<DWORD>(size), NULL);
   if (file_mapping == NULL) return NULL;
   // Map a view of the file into memory
   void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
@@ -896,8 +898,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
 
 
 Win32MemoryMappedFile::~Win32MemoryMappedFile() {
-  if (memory_ != NULL)
-    UnmapViewOfFile(memory_);
+  if (memory_) UnmapViewOfFile(memory_);
   CloseHandle(file_mapping_);
   CloseHandle(file_);
 }
index 1873bbe..2d837ba 100644 (file)
@@ -210,11 +210,13 @@ class OS {
 
   class MemoryMappedFile {
    public:
+    virtual ~MemoryMappedFile() {}
+    virtual void* memory() const = 0;
+    virtual size_t size() const = 0;
+
     static MemoryMappedFile* open(const char* name);
-    static MemoryMappedFile* create(const char* name, int size, void* initial);
-    virtual ~MemoryMappedFile() { }
-    virtual void* memory() = 0;
-    virtual int size() = 0;
+    static MemoryMappedFile* create(const char* name, size_t size,
+                                    void* initial);
   };
 
   // Safe formatting print. Ensures that str is always null-terminated.
index a2594f4..b6a11cf 100644 (file)
@@ -133,7 +133,7 @@ TimeDelta TimeDelta::FromTimespec(struct timespec ts) {
 
 struct timespec TimeDelta::ToTimespec() const {
   struct timespec ts;
-  ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond;
+  ts.tv_sec = static_cast<time_t>(delta_ / Time::kMicrosecondsPerSecond);
   ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) *
       Time::kNanosecondsPerMicrosecond;
   return ts;
@@ -292,7 +292,7 @@ struct timespec Time::ToTimespec() const {
     ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1);  // NOLINT
     return ts;
   }
-  ts.tv_sec = us_ / kMicrosecondsPerSecond;
+  ts.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
   ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond;
   return ts;
 }
@@ -324,7 +324,7 @@ struct timeval Time::ToTimeval() const {
     tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1);
     return tv;
   }
-  tv.tv_sec = us_ / kMicrosecondsPerSecond;
+  tv.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
   tv.tv_usec = us_ % kMicrosecondsPerSecond;
   return tv;
 }
index 9a20b06..3bca14f 100644 (file)
@@ -89,8 +89,9 @@ static bool WaitOnFD(int fd,
   if (total_timeout != -1) {
     struct timeval time_now;
     gettimeofday(&time_now, NULL);
-    int seconds = time_now.tv_sec - start_time.tv_sec;
-    gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000;
+    time_t seconds = time_now.tv_sec - start_time.tv_sec;
+    gone = static_cast<int>(seconds * 1000 +
+                            (time_now.tv_usec - start_time.tv_usec) / 1000);
     if (gone >= total_timeout) return false;
   }
   FD_ZERO(&readfds);
@@ -125,12 +126,12 @@ static bool TimeIsOut(const struct timeval& start_time, const int& total_time) {
   struct timeval time_now;
   gettimeofday(&time_now, NULL);
   // Careful about overflow.
-  int seconds = time_now.tv_sec - start_time.tv_sec;
+  int seconds = static_cast<int>(time_now.tv_sec - start_time.tv_sec);
   if (seconds > 100) {
     if (seconds * 1000 > total_time) return true;
     return false;
   }
-  int useconds = time_now.tv_usec - start_time.tv_usec;
+  int useconds = static_cast<int>(time_now.tv_usec - start_time.tv_usec);
   if (seconds * 1000000 + useconds > total_time * 1000) {
     return true;
   }
@@ -264,7 +265,7 @@ static void ExecSubprocess(int* exec_error_fds,
   // Only get here if the exec failed.  Write errno to the parent to tell
   // them it went wrong.  If it went well the pipe is closed.
   int err = errno;
-  int bytes_written;
+  ssize_t bytes_written;
   do {
     bytes_written = write(exec_error_fds[kWriteFD], &err, sizeof(err));
   } while (bytes_written == -1 && errno == EINTR);
@@ -275,7 +276,7 @@ static void ExecSubprocess(int* exec_error_fds,
 // Runs in the parent process.  Checks that the child was able to exec (closing
 // the file desriptor), or reports an error if it failed.
 static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
-  int bytes_read;
+  ssize_t bytes_read;
   int err;
   do {
     bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
@@ -308,9 +309,8 @@ static Handle<Value> GetStdout(Isolate* isolate,
 
   int bytes_read;
   do {
-    bytes_read = read(child_fd,
-                      buffer + fullness,
-                      kStdoutReadBufferSize - fullness);
+    bytes_read = static_cast<int>(
+        read(child_fd, buffer + fullness, kStdoutReadBufferSize - fullness));
     if (bytes_read == -1) {
       if (errno == EAGAIN) {
         if (!WaitOnFD(child_fd,
index cf44817..8c6d6ba 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1113,17 +1113,21 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
   if (file == NULL) return NULL;
 
   fseek(file, 0, SEEK_END);
-  int size = ftell(file);
+  size_t size = ftell(file);
   rewind(file);
 
   char* chars = new char[size + 1];
   chars[size] = '\0';
-  for (int i = 0; i < size;) {
-    int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
-    i += read;
+  for (size_t i = 0; i < size;) {
+    i += fread(&chars[i], 1, size - i, file);
+    if (ferror(file)) {
+      fclose(file);
+      delete[] chars;
+      return nullptr;
+    }
   }
   fclose(file);
-  *size_out = size;
+  *size_out = static_cast<int>(size);
   return chars;
 }
 
index 7386238..88f06a3 100644 (file)
@@ -394,7 +394,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
           *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
           break;
         case Flag::TYPE_INT:
-          *flag->int_variable() = strtol(value, &endp, 10);  // NOLINT
+          *flag->int_variable() = static_cast<int>(strtol(value, &endp, 10));
           break;
         case Flag::TYPE_FLOAT:
           *flag->float_variable() = strtod(value, &endp);
index 0664c60..2de4e66 100644 (file)
@@ -179,7 +179,7 @@ class DebugSectionBase : public ZoneObject {
     uintptr_t start = writer->position();
     if (WriteBodyInternal(writer)) {
       uintptr_t end = writer->position();
-      header->offset = start;
+      header->offset = static_cast<uint32_t>(start);
 #if defined(__MACH_O)
       header->addr = 0;
 #endif
@@ -465,7 +465,7 @@ class ELFStringTable : public ELFSection {
 
 void ELFSection::PopulateHeader(Writer::Slot<ELFSection::Header> header,
                                 ELFStringTable* strtab) {
-  header->name = strtab->Add(name_);
+  header->name = static_cast<uint32_t>(strtab->Add(name_));
   header->type = type_;
   header->alignment = align_;
   PopulateHeader(header);
@@ -813,7 +813,7 @@ class ELFSymbol BASE_EMBEDDED {
 
   void Write(Writer::Slot<SerializedLayout> s, ELFStringTable* t) {
     // Convert symbol names from strings to indexes in the string table.
-    s->name = t->Add(name);
+    s->name = static_cast<uint32_t>(t->Add(name));
     s->value = value;
     s->size = size;
     s->info = info;
@@ -1638,7 +1638,7 @@ void UnwindInfoSection::WriteLength(Writer* w,
   }
 
   DCHECK((w->position() - initial_position) % kPointerSize == 0);
-  length_slot->set(w->position() - initial_position);
+  length_slot->set(static_cast<uint32_t>(w->position() - initial_position));
 }
 
 
@@ -1653,7 +1653,7 @@ UnwindInfoSection::UnwindInfoSection(CodeDescription* desc)
 
 int UnwindInfoSection::WriteCIE(Writer* w) {
   Writer::Slot<uint32_t> cie_length_slot = w->CreateSlotHere<uint32_t>();
-  uint32_t cie_position = w->position();
+  uint32_t cie_position = static_cast<uint32_t>(w->position());
 
   // Write out the CIE header. Currently no 'common instructions' are
   // emitted onto the CIE; every FDE has its own set of instructions.
@@ -1674,7 +1674,7 @@ int UnwindInfoSection::WriteCIE(Writer* w) {
 void UnwindInfoSection::WriteFDE(Writer* w, int cie_position) {
   // The only FDE for this function. The CFA is the current RBP.
   Writer::Slot<uint32_t> fde_length_slot = w->CreateSlotHere<uint32_t>();
-  int fde_position = w->position();
+  int fde_position = static_cast<uint32_t>(w->position());
   w->Write<int32_t>(fde_position - cie_position + 4);
 
   w->Write<uintptr_t>(desc_->CodeStart());
@@ -2067,7 +2067,8 @@ static void AddJITCodeEntry(CodeMap* map, const AddressRange& range,
 
     SNPrintF(Vector<char>(file_name, kMaxFileNameSize), "/tmp/elfdump%s%d.o",
              (name_hint != NULL) ? name_hint : "", file_num++);
-    WriteBytes(file_name, entry->symfile_addr_, entry->symfile_size_);
+    WriteBytes(file_name, entry->symfile_addr_,
+               static_cast<int>(entry->symfile_size_));
   }
 #endif
 
index 79c1643..f44eca5 100644 (file)
@@ -118,13 +118,13 @@ char* GetExtraCode(char* filename) {
     exit(1);
   }
   fseek(file, 0, SEEK_END);
-  int size = ftell(file);
+  size_t size = ftell(file);
   rewind(file);
   char* chars = new char[size + 1];
   chars[size] = '\0';
-  for (int i = 0; i < size;) {
-    int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
-    if (read < 0) {
+  for (size_t i = 0; i < size;) {
+    size_t read = fread(&chars[i], 1, size - i, file);
+    if (ferror(file)) {
       fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno);
       exit(1);
     }
index c6fe55b..b33e4c2 100644 (file)
@@ -203,7 +203,7 @@ char* ReadCharsFromFile(FILE* file,
   }
 
   // Get the size of the file and rewind it.
-  *size = ftell(file);
+  *size = static_cast<int>(ftell(file));
   rewind(file);
 
   char* result = NewArray<char>(*size + extra_space);
index 30bbe1e..6d8c761 100644 (file)
@@ -128,6 +128,9 @@ struct ParameterTraits<T*> {
   static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); }
 };
 
+
+#if !V8_TARGET_ARCH_32_BIT
+
 // Additional template specialization required for mips64 to sign-extend
 // parameters defined by calling convention.
 template <>
@@ -142,6 +145,9 @@ struct ParameterTraits<uint32_t> {
   }
 };
 
+#endif  // !V8_TARGET_ARCH_64_BIT
+
+
 class CallHelper {
  public:
   explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig)
index 5b7fe56..ec70a4c 100644 (file)
@@ -423,7 +423,7 @@ static intptr_t MemoryInUse() {
 
   const int kBufSize = 10000;
   char buffer[kBufSize];
-  int length = read(fd, buffer, kBufSize);
+  ssize_t length = read(fd, buffer, kBufSize);
   intptr_t line_start = 0;
   CHECK_LT(length, kBufSize);  // Make the buffer bigger.
   CHECK_GT(length, 0);  // We have to find some data in the file.
index 7b51d2f..31bd8ea 100644 (file)
@@ -27,6 +27,8 @@
 
 // Utility functions used by parser-shell.
 
+#include "src/globals.h"
+
 #include <stdio.h>
 
 namespace v8 {
@@ -44,7 +46,7 @@ const byte* ReadFileAndRepeat(const char* name, int* size, int repeat) {
   if (file == NULL) return NULL;
 
   fseek(file, 0, SEEK_END);
-  int file_size = ftell(file);
+  int file_size = static_cast<int>(ftell(file));
   rewind(file);
 
   *size = file_size * repeat;