[llvm] r357058 - [Support] MemoryBlock size should reflect the requested size

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 27 03:26:21 PDT 2019


Author: anng
Date: Wed Mar 27 03:26:21 2019
New Revision: 357058

URL: http://llvm.org/viewvc/llvm-project?rev=357058&view=rev
Log:
[Support] MemoryBlock size should reflect the requested size

This patch mirrors the change made to the Unix equivalent in
r351916. This in turn fixes bugs related to the use of FileOutputBuffer
to output to "-", i.e. stdout, on Windows.

Differential Revision: https://reviews.llvm.org/D59663

Modified:
    llvm/trunk/lib/Support/Windows/Memory.inc

Modified: llvm/trunk/lib/Support/Windows/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Memory.inc?rev=357058&r1=357057&r2=357058&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Memory.inc (original)
+++ llvm/trunk/lib/Support/Windows/Memory.inc Wed Mar 27 03:26:21 2019
@@ -135,8 +135,9 @@ MemoryBlock Memory::allocateMappedMemory
 
   DWORD Protect = getWindowsProtectionFlags(Flags);
 
+  size_t AllocSize = NumBlocks * Granularity;
   void *PA = ::VirtualAlloc(reinterpret_cast<void *>(Start),
-                            NumBlocks * Granularity, AllocType, Protect);
+                            AllocSize, AllocType, Protect);
   if (PA == NULL) {
     if (NearBlock || HugePages) {
       // Try again without the NearBlock hint and without large memory pages
@@ -148,11 +149,11 @@ MemoryBlock Memory::allocateMappedMemory
 
   MemoryBlock Result;
   Result.Address = PA;
-  Result.Size = NumBlocks*Granularity;
+  Result.Size = NumBytes;
   Result.Flags = (Flags & ~MF_HUGE_HINT) | (HugePages ? MF_HUGE_HINT : 0);
 
   if (Flags & MF_EXEC)
-    Memory::InvalidateInstructionCache(Result.Address, Result.Size);
+    Memory::InvalidateInstructionCache(Result.Address, AllocSize);
 
   return Result;
 }




More information about the llvm-commits mailing list