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
I'm not totally happy with the name "safe" here. They're really no "safer", they just have a different failure mode that is hookable. I kind of like mallocOrDie or malloc_or_die, which is the naming used by the sanitizer libraries. Let's leave it alone for now, though.