Intialize memory to zero to silence MSan.

The MemorySanitizer tool can't instrument JIT-compiled code, so it's
unaware that the vertex processing routine writes the clip flags before
they're being read by triangle setup. This false positive can be
silenced by zeroing the memory at allocation. For good measure, zero
out all intermediate buffers.

Bug chromium:737875

Change-Id: Ic37ff5c64cb63bbddb151744af1d7dff0a254c2d
Reviewed-on: https://swiftshader-review.googlesource.com/10431
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Common/Memory.cpp b/src/Common/Memory.cpp
index 2019cae..f946d2f 100644
--- a/src/Common/Memory.cpp
+++ b/src/Common/Memory.cpp
@@ -32,8 +32,6 @@
 
 #undef allocate
 #undef deallocate
-#undef allocateZero
-#undef deallocateZero
 
 #if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined (_M_X64)) && !defined(__x86__)
 #define __x86__
@@ -65,10 +63,10 @@
 	unsigned char *block;
 };
 
-void *allocate(size_t bytes, size_t alignment)
+inline void *allocateRaw(size_t bytes, size_t alignment)
 {
 	unsigned char *block = new unsigned char[bytes + sizeof(Allocation) + alignment];
-	unsigned char *aligned = 0;
+	unsigned char *aligned = nullptr;
 
 	if(block)
 	{
@@ -82,9 +80,9 @@
 	return aligned;
 }
 
-void *allocateZero(size_t bytes, size_t alignment)
+void *allocate(size_t bytes, size_t alignment)
 {
-	void *memory = allocate(bytes, alignment);
+	void *memory = allocateRaw(bytes, alignment);
 
 	if(memory)
 	{
diff --git a/src/Common/Memory.hpp b/src/Common/Memory.hpp
index fc3fd55..8d3a159 100644
--- a/src/Common/Memory.hpp
+++ b/src/Common/Memory.hpp
@@ -23,14 +23,13 @@
 size_t memoryPageSize();
 
 void *allocate(size_t bytes, size_t alignment = 16);
-void *allocateZero(size_t bytes, size_t alignment = 16);
 void deallocate(void *memory);
 
 void *allocateExecutable(size_t bytes);   // Allocates memory that can be made executable using markExecutable()
 void markExecutable(void *memory, size_t bytes);
 void deallocateExecutable(void *memory, size_t bytes);
 
-void clear(uint16_t *memory, uint16_t element, size_t count);

+void clear(uint16_t *memory, uint16_t element, size_t count);
 void clear(uint32_t *memory, uint32_t element, size_t count);
 }
 
diff --git a/src/Common/Resource.cpp b/src/Common/Resource.cpp
index b016c95..e16968a 100644
--- a/src/Common/Resource.cpp
+++ b/src/Common/Resource.cpp
@@ -26,7 +26,7 @@
 		count = 0;
 		orphaned = false;
 
-		buffer = allocateZero(bytes);
+		buffer = allocate(bytes);
 	}
 
 	Resource::~Resource()
diff --git a/src/Renderer/Surface.cpp b/src/Renderer/Surface.cpp
index e964584..6615b4b 100644
--- a/src/Renderer/Surface.cpp
+++ b/src/Renderer/Surface.cpp
@@ -3116,7 +3116,7 @@
 		// FIXME: Unpacking byte4 to short4 in the sampler currently involves reading 8 bytes,
 		// and stencil operations also read 8 bytes per four 8-bit stencil values,
 		// so we have to allocate 4 extra bytes to avoid buffer overruns.
-		return allocateZero(size(width2, height2, depth, format) + 4);
+		return allocate(size(width2, height2, depth, format) + 4);
 	}
 
 	void Surface::memfill4(void *buffer, int pattern, int bytes)