1 // RUN: %clangxx %collect_stack_traces -O0 %s -o %t
3 // Alignment is not a power of 2:
4 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s
5 // Size is not a multiple of alignment:
6 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 8 2>&1 | FileCheck %s
8 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s
10 // The same for allocator_may_return_null=1:
11 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
12 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
13 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
15 // REQUIRES: stable-runtime
17 // UNSUPPORTED: android, ubsan
24 extern void *aligned_alloc(size_t alignment
, size_t size
);
26 int main(int argc
, char **argv
) {
28 const int alignment
= atoi(argv
[1]);
30 void *p
= aligned_alloc(alignment
, 100);
31 // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in aligned_alloc}}
32 // Handle a case when aligned_alloc is aliased by memalign.
33 // CHECK: {{#0 .*}}{{aligned_alloc|memalign}}
34 // CHECK: {{#[12] .*main .*aligned_alloc-alignment.cpp:}}[[@LINE-4]]
35 // CHECK: {{SUMMARY: .*Sanitizer: invalid-aligned-alloc-alignment}}
37 // The NULL pointer is printed differently on different systems, while (long)0
38 // is always the same.
39 fprintf(stderr
, "errno: %d, p: %lx\n", errno
, (long)p
);
40 // CHECK-NULL: errno: 22, p: 0