[LLVM][NVPTX] Add support for griddepcontrol instruction (#123511)
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Linux / pvalloc-overflow.cpp
blobb082191cb0092250a20ea03ca8e5d94406d85da0
1 // RUN: %clangxx %collect_stack_traces -O0 %s -o %t
2 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t m1 2>&1 | FileCheck %s
3 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t m1 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
4 // RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t psm1 2>&1 | FileCheck %s
5 // RUN: %env_tool_opts=allocator_may_return_null=1 %run %t psm1 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
7 // REQUIRES: stable-runtime
9 // UNSUPPORTED: android, target={{.*(freebsd|netbsd).*}}, ubsan
11 // Checks that pvalloc overflows are caught. If the allocator is allowed to
12 // return null, the errno should be set to ENOMEM.
14 #include <assert.h>
15 #include <errno.h>
16 #include <malloc.h>
17 #include <stdio.h>
18 #include <stdint.h>
19 #include <string.h>
20 #include <unistd.h>
22 int main(int argc, char *argv[]) {
23 assert(argc == 2);
24 const char *action = argv[1];
26 const size_t page_size = sysconf(_SC_PAGESIZE);
28 void *p = nullptr;
29 if (!strcmp(action, "m1")) {
30 p = pvalloc((uintptr_t)-1);
31 } else if (!strcmp(action, "psm1")) {
32 p = pvalloc((uintptr_t)-(page_size - 1));
33 } else {
34 assert(0);
36 // CHECK: {{ERROR: .*Sanitizer: pvalloc parameters overflow: size .* rounded up to system page size .* cannot be represented in type size_t}}
37 // CHECK: {{#0 .*pvalloc}}
38 // CHECK: {{#[12] .*main .*pvalloc-overflow.cpp:}}
39 // CHECK: {{SUMMARY: .*Sanitizer: pvalloc-overflow}}
41 // The NULL pointer is printed differently on different systems, while (long)0
42 // is always the same.
43 fprintf(stderr, "errno: %d, p: %lx\n", errno, (long)p);
44 // CHECK-NULL: errno: 12, p: 0
46 return 0;