1 // RUN: %clangxx %collect_stack_traces -O0 %s -o %t
3 // Alignment is not a power of two:
4 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s
5 // Alignment is not a power of two, although is a multiple of sizeof(void*):
6 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 24 2>&1 | FileCheck %s
7 // Alignment is not a multiple of sizeof(void*), although is a power of 2:
8 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 2 2>&1 | FileCheck %s
10 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s
12 // The same for allocator_may_return_null=1:
13 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
14 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 24 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
15 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
16 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
18 // REQUIRES: stable-runtime
27 int main(int argc
, char **argv
) {
29 const int alignment
= atoi(argv
[1]);
31 void* const kInitialPtrValue
= reinterpret_cast<void*>(0x2a);
32 void *p
= kInitialPtrValue
;
35 int res
= posix_memalign(&p
, alignment
, 100);
36 // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in posix_memalign}}
37 // CHECK: {{#0 .*posix_memalign}}
38 // CHECK: {{#[12] .*main .*posix_memalign-alignment.cpp:}}[[@LINE-3]]
39 // CHECK: {{SUMMARY: .*Sanitizer: invalid-posix-memalign-alignment}}
41 // The NULL pointer is printed differently on different systems, while (long)0
42 // is always the same.
43 fprintf(stderr
, "errno: %d, res: %d, p: %lx\n", errno
, res
, (long)p
);
44 // CHECK-NULL: errno: 0, res: 22, p: 2a