1 // RUN: %clangxx_hwasan -O0 %s -o %t
2 // RUN: %env_hwasan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
3 // RUN: %env_hwasan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
4
5 // REQUIRES: stable-runtime
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "../utils.h"
11
main()12 int main() {
13 void *p = reinterpret_cast<void*>(42);
14 int res = posix_memalign(&p, 17, 100);
15 // CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in posix_memalign: 17
16 // CHECK: {{#0 0x.* in .*posix_memalign}}
17 // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cpp:}}[[@LINE-3]]
18 // CHECK: SUMMARY: HWAddressSanitizer: invalid-posix-memalign-alignment
19
20 untag_printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
21 // CHECK-NULL: pointer after failed posix_memalign: 42
22
23 return 0;
24 }
25