[PATCH] D47440: Use uniform mechanism for OOM errors handling

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 28 00:31:19 PDT 2018


sepavloff created this revision.
sepavloff added a reviewer: rnk.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D47440

Files:
  include/llvm/ADT/SmallVector.h
  include/llvm/ADT/StringMap.h
  include/llvm/Support/Allocator.h
  include/llvm/Support/MemAlloc.h
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47440.148784.patch
Type: text/x-patch
Size: 12984 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180528/260f249e/attachment.bin>


More information about the llvm-commits mailing list