llvm-project/llvm/unittests/Support
Serge Pavlov 431502a675 Report fatal error in the case of out of memory
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.

Usual programming practice does not require checking result of 'operator
new' because it throws 'std::bad_alloc' in the case of allocation error.
However, LLVM is usually built with exceptions turned off, so 'new' can
return null pointer. This change installs custom new handler, which causes
fatal error in the case of out of memory. The handler is installed
automatically prior to call to 'main' during construction of a static
object defined in 'lib/Support/ErrorHandling.cpp'. If the application does
not use this file, the handler may be installed manually by a call to
'llvm::install_out_of_memory_new_handler', declared in
'include/llvm/Support/ErrorHandling.h".

There are calls to 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 against null pointer. To simplify
checks, new functions are defined in the namespace 'llvm' with the
same names as these C function. These functions produce fatal error if
allocation fails. User should use 'llvm::malloc' instead of 'std::malloc'
in order to use the safe variant. This change replaces 'std::malloc'
in the cases when the result of allocation function is not checked against
null pointer.

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

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

llvm-svn: 325224
2018-02-15 09:20:26 +00:00
..
DynamicLibrary [CMake] Use PRIVATE in target_link_libraries for executables 2017-12-05 21:49:56 +00:00
ARMAttributeParser.cpp Remove redundant includes from unittests. 2017-12-13 21:31:05 +00:00
AlignOfTest.cpp
AllocatorTest.cpp Report fatal error in the case of out of memory 2018-02-15 09:20:26 +00:00
ArrayRecyclerTest.cpp
BinaryStreamTest.cpp Remove redundant includes from unittests. 2017-12-13 21:31:05 +00:00
BlockFrequencyTest.cpp
BranchProbabilityTest.cpp
CMakeLists.txt Revert r325107 (case folding DJB hash) and subsequent build fix 2018-02-14 11:06:39 +00:00
CachePruningTest.cpp Unbreak the build. Combining chrono with Optional is annoying. 2017-12-22 21:18:50 +00:00
Casting.cpp
Chrono.cpp Support formatv of TimePoint with strftime-style formats. 2017-10-24 08:30:19 +00:00
CommandLineTest.cpp Added support for reading configuration files 2017-12-30 15:37:46 +00:00
CompressionTest.cpp
ConvertUTFTest.cpp Remove redundant includes from unittests. 2017-12-13 21:31:05 +00:00
CrashRecoveryTest.cpp
DataExtractorTest.cpp
DebugTest.cpp
EndianStreamTest.cpp
EndianTest.cpp
ErrnoTest.cpp Recommit "[Support] Add RetryAfterSignal helper function" 2017-06-29 13:15:31 +00:00
ErrorOrTest.cpp Fix incorrect usage of std::is_assignable. 2018-02-02 22:29:54 +00:00
ErrorTest.cpp [Testing/Support] Make the HasValue matcher composable 2017-12-13 10:00:38 +00:00
FileOutputBufferTest.cpp Convert FileOutputBuffer::commit to Error. 2017-11-08 01:50:29 +00:00
FormatVariadicTest.cpp Fix FormatVariadicTest with GCC 2017-10-23 18:41:22 +00:00
GlobPatternTest.cpp [Support/GlobPattern] - Do not crash when pattern has characters with int value < 0. 2017-07-31 09:26:50 +00:00
Host.cpp [AArch64] Add Exynos to host detection 2017-12-08 21:09:59 +00:00
LEB128Test.cpp Change encodeU/SLEB128 to pad to certain number of bytes 2017-09-15 20:34:47 +00:00
LineIteratorTest.cpp
LockFileManagerTest.cpp
MD5Test.cpp
ManagedStatic.cpp Report fatal error in the case of out of memory 2018-02-15 09:20:26 +00:00
MathExtrasTest.cpp MathExtras UnitTest: Assert that isPowerOf2(0) is false. NFC. 2017-07-03 18:42:47 +00:00
MemoryBufferTest.cpp [Support] Add WritableMemoryBuffer::getNewMemBuffer 2018-01-09 17:26:06 +00:00
MemoryTest.cpp Untabify. 2017-10-18 13:31:28 +00:00
NativeFormatTests.cpp
ParallelTest.cpp
Path.cpp [Support] Use realpath(3) instead of trying to open a file. 2018-01-09 17:27:45 +00:00
ProcessTest.cpp [Support] env vars with empty values on windows 2017-08-18 16:55:44 +00:00
ProgramTest.cpp Convenience/safety fix for llvm::sys::Execute(And|No)Wait 2017-09-13 17:03:37 +00:00
RegexTest.cpp Fix llvm-special-case-list-fuzzer regexp exception 2017-10-27 19:15:13 +00:00
ReplaceFileTest.cpp Support: Rewrite Windows implementation of sys::fs::rename to be more POSIXy. 2017-10-06 17:14:36 +00:00
ReverseIterationTest.cpp [unittest/ReverseIteration] Unbreak when compiling with GCC. 2017-09-05 21:27:23 +00:00
ScaledNumberTest.cpp
SourceMgrTest.cpp Add DK_Remark to SMDiagnostic 2017-10-12 23:56:02 +00:00
SpecialCaseListTest.cpp Extend SpecialCaseList to allow users to blame matches on entries in the file. 2017-11-07 21:16:46 +00:00
StringPool.cpp
SwapByteOrderTest.cpp
TarWriterTest.cpp Fix build bot after r319750 "[Support/TarWriter] - Don't allow TarWriter to add the same file more than once." 2017-12-05 10:35:11 +00:00
TargetParserTest.cpp Fix signed/unsigned compare warning I introduced 2018-02-08 17:11:32 +00:00
ThreadLocalTest.cpp
ThreadPool.cpp
Threading.cpp
TimerTest.cpp
TrailingObjectsTest.cpp
TrigramIndexTest.cpp
TypeNameTest.cpp
UnicodeTest.cpp
YAMLIOTest.cpp [YAML] Plain scalars can not begin with most indicators. 2018-01-22 10:20:48 +00:00
YAMLParserTest.cpp [YAMLParser] Don't crash on null keys in KeyValueNodes. 2017-11-23 20:57:20 +00:00
formatted_raw_ostream_test.cpp
raw_ostream_test.cpp Support: Add llvm::center_justify. 2017-07-13 16:11:08 +00:00
raw_pwrite_stream_test.cpp
raw_sha1_ostream_test.cpp
xxhashTest.cpp