diff options
author | Alex Shlyapnikov <alekseys@google.com> | 2018-06-18 20:03:31 +0000 |
---|---|---|
committer | Alex Shlyapnikov <alekseys@google.com> | 2018-06-18 20:03:31 +0000 |
commit | 65e9e301b969895edfeadc2fedec84b15430ad42 (patch) | |
tree | aea9d240244bd18f1349999105d36df4927c5dd4 /test/sanitizer_common/TestCases/Posix | |
parent | 3555ac91fdb74c57b2dcc7cfc8ba37ae99dfba67 (diff) | |
download | compiler-rt-65e9e301b969895edfeadc2fedec84b15430ad42.tar.gz |
[TSan] Report proper error on allocator failures instead of CHECK(0)-ing
Summary:
Following up on and complementing D44404 and other sanitizer allocators.
Currently many allocator specific errors (OOM, for example) are reported as
a text message and CHECK(0) termination, no stack, no details, not too
helpful nor informative. To improve the situation, detailed and structured
common errors were defined and reported under the appropriate conditions.
Common tests were generalized a bit to cover a slightly different TSan
stack reporting format, extended to verify errno value and returned
pointer value check is now explicit to facilitate debugging.
Reviewers: dvyukov
Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D48087
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334975 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix')
-rw-r--r-- | test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc b/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc index c46540b6b..7729057d2 100644 --- a/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc +++ b/test/sanitizer_common/TestCases/Posix/posix_memalign-alignment.cc @@ -1,14 +1,26 @@ // RUN: %clangxx %collect_stack_traces -O0 %s -o %t + +// Alignment is not a power of two: // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s +// Alignment is not a power of two, although is a multiple of sizeof(void*): +// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 24 2>&1 | FileCheck %s +// Alignment is not a multiple of sizeof(void*), although is a power of 2: +// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 2 2>&1 | FileCheck %s +// Alignment is 0: // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s + +// The same for allocator_may_return_null=1: // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL +// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 24 2>&1 | FileCheck %s --check-prefix=CHECK-NULL +// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-NULL // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL // REQUIRES: stable-runtime -// UNSUPPORTED: tsan, ubsan +// UNSUPPORTED: ubsan #include <assert.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -16,16 +28,20 @@ int main(int argc, char **argv) { assert(argc == 2); const int alignment = atoi(argv[1]); - void *p = reinterpret_cast<void*>(42); + void* const kInitialPtrValue = reinterpret_cast<void*>(0x2a); + void *p = kInitialPtrValue; + errno = 0; int res = posix_memalign(&p, alignment, 100); // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in posix_memalign}} - // CHECK: {{#0 0x.* in .*posix_memalign}} - // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cc:}}[[@LINE-3]] + // CHECK: {{#0 .*posix_memalign}} + // CHECK: {{#1 .*main .*posix_memalign-alignment.cc:}}[[@LINE-3]] // CHECK: {{SUMMARY: .*Sanitizer: invalid-posix-memalign-alignment}} - printf("pointer after failed posix_memalign: %zd\n", (size_t)p); - // CHECK-NULL: pointer after failed posix_memalign: 42 + // The NULL pointer is printed differently on different systems, while (long)0 + // is always the same. + fprintf(stderr, "errno: %d, res: %d, p: %lx\n", errno, res, (long)p); + // CHECK-NULL: errno: 0, res: 22, p: 2a return 0; } |