Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / posix_memalign-alignment.cpp
blob70fba25f59b847177c3c53cec22216f8a7dfe2eb
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
9 // Alignment is 0:
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
20 // UNSUPPORTED: ubsan
22 #include <assert.h>
23 #include <errno.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 int main(int argc, char **argv) {
28 assert(argc == 2);
29 const int alignment = atoi(argv[1]);
31 void* const kInitialPtrValue = reinterpret_cast<void*>(0x2a);
32 void *p = kInitialPtrValue;
34 errno = 0;
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
46 return 0;