components/llvm/patches/012-TypeLocBuilder.cpp.patch
changeset 5434 9f55c805ce9d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/llvm/patches/012-TypeLocBuilder.cpp.patch	Wed Feb 10 11:54:12 2016 -0800
@@ -0,0 +1,73 @@
+# https://llvm.org/bugs/show_bug.cgi?id=24615
+--- tools/clang/lib/Sema/TypeLocBuilder.h	2014-08-13 09:25:19.000000000 -0700
++++ tools/clang/lib/Sema/TypeLocBuilder.h	2015-08-28 16:45:41.733661825 -0700
+@@ -39,7 +39,7 @@
+ #endif
+     
+   /// The inline buffer.
+-  enum { BufferMaxAlignment = llvm::AlignOf<void*>::Alignment };
++  enum { BufferMaxAlignment = llvm::AlignOf<uint64_t>::Alignment };
+   llvm::AlignedCharArray<BufferMaxAlignment, InlineCapacity> InlineBuffer;
+   unsigned NumBytesAtAlign4, NumBytesAtAlign8;
+ 
+@@ -52,7 +52,7 @@
+ 
+   ~TypeLocBuilder() {
+     if (Buffer != InlineBuffer.buffer)
+-      delete[] Buffer;
++      std::free(Buffer);
+   }
+ 
+   /// Ensures that this buffer has at least as much capacity as described.
+--- tools/clang/lib/Sema/TypeLocBuilder.cpp	2014-05-25 23:22:03.000000000 -0700
++++ tools/clang/lib/Sema/TypeLocBuilder.cpp	2015-08-25 18:53:43.000000000 -0700
+@@ -13,6 +13,8 @@
+ //===----------------------------------------------------------------------===//
+ 
+ #include "TypeLocBuilder.h"
++#include <cstring>
++#include <stdlib.h>
+ 
+ using namespace clang;
+ 
+@@ -46,14 +48,36 @@
+   assert(NewCapacity > Capacity);
+ 
+   // Allocate the new buffer and copy the old data into it.
+-  char *NewBuffer = new char[NewCapacity];
++  char *NewBuffer;
++
++#if defined(_MSC_VER)
++  NewBuffer = _aligned_malloc(NewCapacity, (size_t) BufferMaxAlignment);
++  assert(NewBuffer && "_aligned_malloc failed!");
++  if (!NewBuffer) {
++    llvm::errs() << __PRETTY_FUNCTION__ << ": _aligned_malloc failed!\n";
++    abort();
++  }
++#else
++  int R = posix_memalign((void**) &NewBuffer,
++                         (size_t) BufferMaxAlignment, NewCapacity);
++  assert((R == 0) && "posix_memalign failed!");
++  assert(NewBuffer && "posix_memalign failed!");
++  if ((R != 0) || (!NewBuffer)) {
++    llvm::errs() << __PRETTY_FUNCTION__ << ": posix_memalign failed!\n";
++    abort();
++  }
++#endif
++
++  (void) std::memset(NewBuffer, 0, NewCapacity);
++
+   unsigned NewIndex = Index + NewCapacity - Capacity;
+-  memcpy(&NewBuffer[NewIndex],
++  (void) std::memcpy(&NewBuffer[NewIndex],
+          &Buffer[Index],
+          Capacity - Index);
+ 
+-  if (Buffer != InlineBuffer.buffer)
+-    delete[] Buffer;
++  if (Buffer != InlineBuffer.buffer) {
++    std::free(Buffer);
++  }
+ 
+   Buffer = NewBuffer;
+   Capacity = NewCapacity;