summaryrefslogtreecommitdiff
path: root/lib/asan/tests
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2017-07-14 22:23:47 +0000
committerAlex Shlyapnikov <alekseys@google.com>2017-07-14 22:23:47 +0000
commitdd3d6da1dfc6833e39650a23b570a81b1e85aff8 (patch)
treeca6c6cfc94a0473fdeb5183abea825d2590e1eb3 /lib/asan/tests
parent2706e2583c3e18af76761f5907e981d831850eff (diff)
[Sanitizers] ASan and LSan allocator set errno on failure.
Summary: Set proper errno code on alloction failures and change some implementations to satisfy their man-specified requirements: LSan: valloc and memalign ASan: pvalloc, memalign and posix_memalign Changing both allocators in one patch since LSan depends on ASan allocator in some configurations. Reviewers: vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D35440 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308064 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/tests')
-rw-r--r--lib/asan/tests/asan_test.cc18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/asan/tests/asan_test.cc b/lib/asan/tests/asan_test.cc
index d0128e34d..78c3a0e4e 100644
--- a/lib/asan/tests/asan_test.cc
+++ b/lib/asan/tests/asan_test.cc
@@ -12,6 +12,8 @@
//===----------------------------------------------------------------------===//
#include "asan_test_utils.h"
+#include <errno.h>
+
NOINLINE void *malloc_fff(size_t size) {
void *res = malloc/**/(size); break_optimization(0); return res;}
NOINLINE void *malloc_eee(size_t size) {
@@ -74,10 +76,19 @@ TEST(AddressSanitizer, VariousMallocsTest) {
delete c;
#if SANITIZER_TEST_HAS_POSIX_MEMALIGN
- int *pm;
- int pm_res = posix_memalign((void**)&pm, kPageSize, kPageSize);
+ void *pm = 0;
+ // Valid allocation.
+ int pm_res = posix_memalign(&pm, kPageSize, kPageSize);
EXPECT_EQ(0, pm_res);
+ EXPECT_NE(nullptr, pm);
free(pm);
+
+ // Alignment is not a power of 2.
+ EXPECT_DEATH(posix_memalign(&pm, 3, kPageSize),
+ "allocator is terminating the process instead of returning 0");
+ // Alignment is a power of 2, but not a multiple of size(void *).
+ EXPECT_DEATH(posix_memalign(&pm, 2, kPageSize),
+ "allocator is terminating the process instead of returning 0");
#endif // SANITIZER_TEST_HAS_POSIX_MEMALIGN
#if SANITIZER_TEST_HAS_MEMALIGN
@@ -85,6 +96,9 @@ TEST(AddressSanitizer, VariousMallocsTest) {
EXPECT_EQ(0U, (uintptr_t)ma % kPageSize);
ma[123] = 0;
free(ma);
+
+ EXPECT_DEATH(memalign(3, kPageSize),
+ "allocator is terminating the process instead of returning 0");
#endif // SANITIZER_TEST_HAS_MEMALIGN
}