MemoryBuffer.cpp: Don't peek the next page if file is multiple of *physical* pagesize...
authorNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 4 Sep 2013 14:12:19 +0000 (14:12 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Wed, 4 Sep 2013 14:12:19 +0000 (14:12 +0000)
For example, r189780's SparcISelLowering.cpp has the size 98304. It crashed clang to touch a null terminator on cygwin.

FIXME: It's not good to hardcode 4096 here. dwPageSize shows 4096.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189939 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/MemoryBuffer.cpp

index 1134f5bb53e91302930e492f3fd792b03d898b2f..e018ad4ecce31b6ef59b7667b6861419a10cc33e 100644 (file)
@@ -302,6 +302,15 @@ static bool shouldUseMmap(int FD,
   if (End != FileSize)
     return false;
 
+#if defined(_WIN32) || defined(__CYGWIN__)
+  // Don't peek the next page if file is multiple of *physical* pagesize(4k)
+  // but is not multiple of AllocationGranularity(64k),
+  // when a null terminator is required.
+  // FIXME: It's not good to hardcode 4096 here. dwPageSize shows 4096.
+  if ((FileSize & (4096 - 1)) == 0)
+    return false;
+#endif
+
   // Don't try to map files that are exactly a multiple of the system page size
   // if we need a null terminator.
   if ((FileSize & (PageSize -1)) == 0)