OSDN Git Service

Use uniform mechanism for OOM errors handling
authorSerge Pavlov <sepavloff@gmail.com>
Tue, 29 May 2018 05:39:08 +0000 (05:39 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Tue, 29 May 2018 05:39:08 +0000 (05:39 +0000)
commit5c9fd60f9fcbf145835167bd51dd2d4fa57f19d5
tree58f695922d0089c43961d9b7a9d87f7212fe9766
parent7cdb0e22c2bc1d404452681c7942995d939f8b30
Use uniform mechanism for OOM errors handling

In r325551 many calls of malloc/calloc/realloc were replaces with calls of
their safe counterparts defined in the namespace llvm. There functions
generate crash if memory cannot be allocated, such behavior facilitates
handling of out of memory errors on Windows.

If the result of *alloc function were checked for success, the function was
not replaced with the safe variant. In these cases the calling function made
the error handling, like:

    T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T)));
    if (NewElts == nullptr)
      report_bad_alloc_error("Allocation of SmallVector element failed.");

Actually knowledge about the function where OOM occurred is useless. Moreover
having a single entry point for OOM handling is convenient for investigation
of memory problems. This change removes custom OOM errors handling and
replaces them with calls to functions `llvm::safe_*alloc`.

Declarations of `safe_*alloc` are moved to a separate include file, to avoid
cyclic dependency in SmallVector.h

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333390 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/SmallVector.h
include/llvm/ADT/StringMap.h
include/llvm/Support/Allocator.h
include/llvm/Support/MemAlloc.h [new file with mode: 0644]
lib/Demangle/ItaniumDemangle.cpp
lib/IR/DataLayout.cpp
lib/Support/FoldingSet.cpp
lib/Support/Mutex.cpp
lib/Support/SmallPtrSet.cpp
lib/Support/SmallVector.cpp
lib/Support/StringMap.cpp