[llvm] r333518 - Revert commit 333506

Serge Pavlov via llvm-commits llvm-commits at lists.llvm.org
Wed May 30 02:01:12 PDT 2018


Author: sepavloff
Date: Wed May 30 02:01:12 2018
New Revision: 333518

URL: http://llvm.org/viewvc/llvm-project?rev=333518&view=rev
Log:
Revert commit 333506

It looks like this commit is responsible for the fail:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/24382.

Removed:
    llvm/trunk/include/llvm/Support/MemAlloc.h
Modified:
    llvm/trunk/include/llvm/ADT/SmallVector.h
    llvm/trunk/include/llvm/ADT/StringMap.h
    llvm/trunk/include/llvm/Support/Allocator.h
    llvm/trunk/lib/IR/DataLayout.cpp
    llvm/trunk/lib/Support/FoldingSet.cpp
    llvm/trunk/lib/Support/Mutex.cpp
    llvm/trunk/lib/Support/SmallPtrSet.cpp
    llvm/trunk/lib/Support/SmallVector.cpp
    llvm/trunk/lib/Support/StringMap.cpp

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed May 30 02:01:12 2018
@@ -18,7 +18,6 @@
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/MemAlloc.h"
 #include "llvm/Support/type_traits.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <algorithm>
@@ -239,7 +238,9 @@ void SmallVectorTemplateBase<T, isPodLik
   size_t NewCapacity = size_t(NextPowerOf2(CurCapacity+2));
   if (NewCapacity < MinSize)
     NewCapacity = MinSize;
-  T *NewElts = static_cast<T*>(llvm::safe_malloc(NewCapacity*sizeof(T)));
+  T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T)));
+  if (NewElts == nullptr)
+    report_bad_alloc_error("Allocation of SmallVector element failed.");
 
   // Move the elements over.
   this->uninitialized_move(this->begin(), this->end(), NewElts);

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Wed May 30 02:01:12 2018
@@ -164,7 +164,9 @@ public:
 
     StringMapEntry *NewItem =
       static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
-    assert(NewItem && "Unhandled out-of-memory");
+
+    if (NewItem == nullptr)
+      report_bad_alloc_error("Allocation of StringMap entry failed.");
 
     // Construct the value.
     new (NewItem) StringMapEntry(KeyLength, std::forward<InitTy>(InitVals)...);

Modified: llvm/trunk/include/llvm/Support/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Allocator.h?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Allocator.h (original)
+++ llvm/trunk/include/llvm/Support/Allocator.h Wed May 30 02:01:12 2018
@@ -23,9 +23,8 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/MemAlloc.h"
+#include "llvm/Support/ErrorHandling.h"
 #include <algorithm>
 #include <cassert>
 #include <cstddef>
@@ -96,7 +95,11 @@ public:
 
   LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size,
                                                 size_t /*Alignment*/) {
-    return safe_malloc(Size);
+    void* memPtr =  malloc(Size);
+    if (memPtr == nullptr) 
+      report_bad_alloc_error("Allocation in MallocAllocator failed.");
+
+    return memPtr;
   }
 
   // Pull in base class overloads.
@@ -436,6 +439,34 @@ public:
   T *Allocate(size_t num = 1) { return Allocator.Allocate<T>(num); }
 };
 
+/// \{
+/// Counterparts of allocation functions defined in namespace 'std', which crash
+/// on allocation failure instead of returning null pointer.
+
+LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {
+  void *Result = std::malloc(Sz);
+  if (Result == nullptr)
+    report_bad_alloc_error("Allocation failed.");
+  return Result;
+}
+
+LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_calloc(size_t Count,
+                                                        size_t Sz) {
+  void *Result = std::calloc(Count, Sz);
+  if (Result == nullptr)
+    report_bad_alloc_error("Allocation failed.");
+  return Result;
+}
+
+LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_realloc(void *Ptr, size_t Sz) {
+  void *Result = std::realloc(Ptr, Sz);
+  if (Result == nullptr)
+    report_bad_alloc_error("Allocation failed.");
+  return Result;
+}
+
+/// \}
+
 } // end namespace llvm
 
 template <typename AllocatorT, size_t SlabSize, size_t SizeThreshold>

Removed: llvm/trunk/include/llvm/Support/MemAlloc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemAlloc.h?rev=333517&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Support/MemAlloc.h (original)
+++ llvm/trunk/include/llvm/Support/MemAlloc.h (removed)
@@ -1,49 +0,0 @@
-//===- MemAlloc.h - Memory allocation functions -----------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-/// \file
-///
-/// This file defines counterparts of C library allocation functions defined in
-/// the namespace 'std'. The new allocation functions crash on allocation
-/// failure instead of returning null pointer.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_MEMALLOC_H
-#define LLVM_SUPPORT_MEMALLOC_H
-
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/ErrorHandling.h"
-#include <cstdlib>
-
-namespace llvm {
-
-LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {
-  void *Result = std::malloc(Sz);
-  if (Result == nullptr)
-    report_bad_alloc_error("Allocation failed");
-  return Result;
-}
-
-LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_calloc(size_t Count,
-                                                        size_t Sz) {
-  void *Result = std::calloc(Count, Sz);
-  if (Result == nullptr)
-    report_bad_alloc_error("Allocation failed");
-  return Result;
-}
-
-LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_realloc(void *Ptr, size_t Sz) {
-  void *Result = std::realloc(Ptr, Sz);
-  if (Result == nullptr)
-    report_bad_alloc_error("Allocation failed");
-  return Result;
-}
-
-}
-#endif

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Wed May 30 02:01:12 2018
@@ -596,8 +596,10 @@ const StructLayout *DataLayout::getStruc
   // Otherwise, create the struct layout.  Because it is variable length, we
   // malloc it, then use placement new.
   int NumElts = Ty->getNumElements();
-  StructLayout *L = (StructLayout *)
-      safe_malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t));
+  StructLayout *L =
+    (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t));
+  if (L == nullptr)
+    report_bad_alloc_error("Allocation of StructLayout elements failed.");
 
   // Set SL before calling StructLayout's ctor.  The ctor could cause other
   // entries to be added to TheMap, invalidating our reference.

Modified: llvm/trunk/lib/Support/FoldingSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FoldingSet.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FoldingSet.cpp (original)
+++ llvm/trunk/lib/Support/FoldingSet.cpp Wed May 30 02:01:12 2018
@@ -214,8 +214,11 @@ static void **GetBucketFor(unsigned Hash
 
 /// AllocateBuckets - Allocated initialized bucket memory.
 static void **AllocateBuckets(unsigned NumBuckets) {
-  void **Buckets = static_cast<void**>(safe_calloc(NumBuckets + 1,
-                                                   sizeof(void*)));
+  void **Buckets = static_cast<void**>(calloc(NumBuckets+1, sizeof(void*)));
+
+  if (Buckets == nullptr)
+    report_bad_alloc_error("Allocation of Buckets failed.");
+  
   // Set the very last bucket to be a non-null "pointer".
   Buckets[NumBuckets] = reinterpret_cast<void*>(-1);
   return Buckets;

Modified: llvm/trunk/lib/Support/Mutex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Mutex.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Mutex.cpp (original)
+++ llvm/trunk/lib/Support/Mutex.cpp Wed May 30 02:01:12 2018
@@ -47,7 +47,10 @@ MutexImpl::MutexImpl( bool recursive)
 {
   // Declare the pthread_mutex data structures
   pthread_mutex_t* mutex =
-    static_cast<pthread_mutex_t*>(safe_malloc(sizeof(pthread_mutex_t)));
+    static_cast<pthread_mutex_t*>(malloc(sizeof(pthread_mutex_t)));
+
+  if (mutex == nullptr)
+    report_bad_alloc_error("Mutex allocation failed");
 
   pthread_mutexattr_t attr;
 

Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ llvm/trunk/lib/Support/SmallPtrSet.cpp Wed May 30 02:01:12 2018
@@ -32,7 +32,9 @@ void SmallPtrSetImplBase::shrink_and_cle
   NumNonEmpty = NumTombstones = 0;
 
   // Install the new array.  Clear all the buckets to empty.
-  CurArray = (const void**)safe_malloc(sizeof(void*) * CurArraySize);
+  CurArray = (const void**)malloc(sizeof(void*) * CurArraySize);
+  if (CurArray == nullptr)
+    report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
 
   memset(CurArray, -1, CurArraySize*sizeof(void*));
 }
@@ -98,7 +100,9 @@ void SmallPtrSetImplBase::Grow(unsigned
   bool WasSmall = isSmall();
 
   // Install the new array.  Clear all the buckets to empty.
-  const void **NewBuckets = (const void**) safe_malloc(sizeof(void*) * NewSize);
+  const void **NewBuckets = (const void**) malloc(sizeof(void*) * NewSize);
+  if (NewBuckets == nullptr)
+    report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
 
   // Reset member only if memory was allocated successfully
   CurArray = NewBuckets;
@@ -128,7 +132,9 @@ SmallPtrSetImplBase::SmallPtrSetImplBase
     CurArray = SmallArray;
   // Otherwise, allocate new heap space (unless we were the same size)
   } else {
-    CurArray = (const void**)safe_malloc(sizeof(void*) * that.CurArraySize);
+    CurArray = (const void**)malloc(sizeof(void*) * that.CurArraySize);
+    if (CurArray == nullptr)
+      report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
   }
 
   // Copy over the that array.
@@ -157,12 +163,16 @@ void SmallPtrSetImplBase::CopyFrom(const
   // Otherwise, allocate new heap space (unless we were the same size)
   } else if (CurArraySize != RHS.CurArraySize) {
     if (isSmall())
-      CurArray = (const void**)safe_malloc(sizeof(void*) * RHS.CurArraySize);
+      CurArray = (const void**)malloc(sizeof(void*) * RHS.CurArraySize);
     else {
-      const void **T = (const void**)safe_realloc(CurArray,
+      const void **T = (const void**)realloc(CurArray,
                                              sizeof(void*) * RHS.CurArraySize);
+      if (!T)
+        free(CurArray);
       CurArray = T;
     }
+    if (CurArray == nullptr)
+      report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
   }
 
   CopyHelper(RHS);

Modified: llvm/trunk/lib/Support/SmallVector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallVector.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallVector.cpp (original)
+++ llvm/trunk/lib/Support/SmallVector.cpp Wed May 30 02:01:12 2018
@@ -25,13 +25,17 @@ void SmallVectorBase::grow_pod(void *Fir
 
   void *NewElts;
   if (BeginX == FirstEl) {
-    NewElts = safe_malloc(NewCapacityInBytes);
+    NewElts = malloc(NewCapacityInBytes);
+    if (NewElts == nullptr)
+      report_bad_alloc_error("Allocation of SmallVector element failed.");
 
     // Copy the elements over.  No need to run dtors on PODs.
     memcpy(NewElts, this->BeginX, CurSizeBytes);
   } else {
     // If this wasn't grown from the inline copy, grow the allocated space.
-    NewElts = safe_realloc(this->BeginX, NewCapacityInBytes);
+    NewElts = realloc(this->BeginX, NewCapacityInBytes);
+    if (NewElts == nullptr)
+      report_bad_alloc_error("Reallocation of SmallVector element failed.");
   }
 
   this->EndX = (char*)NewElts+CurSizeBytes;

Modified: llvm/trunk/lib/Support/StringMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringMap.cpp?rev=333518&r1=333517&r2=333518&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringMap.cpp (original)
+++ llvm/trunk/lib/Support/StringMap.cpp Wed May 30 02:01:12 2018
@@ -59,8 +59,10 @@ void StringMapImpl::init(unsigned InitSi
   NumTombstones = 0;
 
   TheTable = static_cast<StringMapEntryBase **>(
-      safe_calloc(NewNumBuckets+1,
+      std::calloc(NewNumBuckets+1,
                   sizeof(StringMapEntryBase **) + sizeof(unsigned)));
+  if (TheTable == nullptr)
+    report_bad_alloc_error("Allocation of StringMap table failed.");
 
   // Set the member only if TheTable was successfully allocated
   NumBuckets = NewNumBuckets;
@@ -218,7 +220,9 @@ unsigned StringMapImpl::RehashTable(unsi
   // Allocate one extra bucket which will always be non-empty.  This allows the
   // iterators to stop at end.
   auto NewTableArray = static_cast<StringMapEntryBase **>(
-      safe_calloc(NewSize+1, sizeof(StringMapEntryBase *) + sizeof(unsigned)));
+      std::calloc(NewSize+1, sizeof(StringMapEntryBase *) + sizeof(unsigned)));
+  if (NewTableArray == nullptr)
+    report_bad_alloc_error("Allocation of StringMap hash table failed.");
 
   unsigned *NewHashArray = (unsigned *)(NewTableArray + NewSize + 1);
   NewTableArray[NewSize] = (StringMapEntryBase*)2;




More information about the llvm-commits mailing list