llvm-project/llvm/lib/Support/Windows
Serge Pavlov 76d8ccee2e Report fatal error in the case of out of memory
This is the second part of recommit of r325224. The previous part was
committed in r325426, which deals with C++ memory allocation. Solution
for C memory allocation involved functions `llvm::malloc` and similar.
This was a fragile solution because it caused ambiguity errors in some
cases. In this commit the new functions have names like `llvm::safe_malloc`.

The relevant part of original comment is below, updated for new function
names.

Analysis of fails in the case of out of memory errors can be tricky on
Windows. Such error emerges at the point where memory allocation function
fails, but manifests itself when null pointer is used. These two points
may be distant from each other. Besides, next runs may not exhibit
allocation error.

In some cases memory is allocated by a call to some of C allocation
functions, malloc, calloc and realloc. They are used for interoperability
with C code, when allocated object has variable size and when it is
necessary to avoid call of constructors. In many calls the result is not
checked for null pointer. To simplify checks, new functions are defined
in the namespace 'llvm': `safe_malloc`, `safe_calloc` and `safe_realloc`.
They behave as corresponding standard functions but produce fatal error if
allocation fails. This change replaces the standard functions like 'malloc'
in the cases when the result of the allocation function is not checked
for null pointer.

Finally, there are plain C code, that uses malloc and similar functions. If
the result is not checked, assert statement is added.

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

llvm-svn: 325551
2018-02-20 05:41:26 +00:00
..
COM.inc
DynamicLibrary.inc Allow clients to specify search order of DynamicLibraries. 2017-07-12 21:22:45 +00:00
Host.inc Update the Windows version of updateTripleOSVersion to account for 2017-07-07 10:08:52 +00:00
Memory.inc [Support] Support NetBSD PaX MPROTECT in sys::Memory. 2017-11-16 23:04:44 +00:00
Mutex.inc Remove more name space pollution from .inc files 2017-03-31 14:26:44 +00:00
Path.inc Call FlushFileBuffers on output files. 2018-02-15 18:36:10 +00:00
Process.inc [Support] env vars with empty values on windows 2017-08-18 16:55:44 +00:00
Program.inc Convenience/safety fix for llvm::sys::Execute(And|No)Wait 2017-09-13 17:03:37 +00:00
RWMutex.inc Report fatal error in the case of out of memory 2018-02-20 05:41:26 +00:00
Signals.inc Typo fix SIBABRT -> SIGABRT. 2018-01-18 21:45:51 +00:00
ThreadLocal.inc Remove more name space pollution from .inc files 2017-03-31 14:26:44 +00:00
Threading.inc Fix C2712 build error on Windows 2017-03-07 20:09:46 +00:00
Watchdog.inc
WindowsSupport.h Fix one place where I missed a commented requirement for a particular 2017-06-06 12:11:24 +00:00
explicit_symbols.inc