[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / test / asan / TestCases / Windows / rtlallocateheap_flags_fallback.cpp
blobc93f1b8151d1bd102f08f1c99362946d09505bbb
1 // RUN: %clang_cl_asan %Od %s %Fe%t %MD
2 // RUN: %env_asan_opts=windows_hook_rtl_allocators=true %run %t 2>&1 | FileCheck %s
3 // UNSUPPORTED: asan-64-bits
5 #include <assert.h>
6 #include <stdio.h>
7 #include <windows.h>
9 extern "C" int __sanitizer_get_ownership(const volatile void *p);
10 using AllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, SIZE_T);
11 using FreeFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID);
13 int main() {
14 HMODULE NtDllHandle = GetModuleHandle("ntdll.dll");
15 if (!NtDllHandle) {
16 puts("Couldn't load ntdll??");
17 return -1;
20 auto RtlAllocateHeap_ptr = (AllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlAllocateHeap");
21 if (RtlAllocateHeap_ptr == 0) {
22 puts("Couldn't RtlAllocateHeap");
23 return -1;
26 auto RtlFreeHeap_ptr = (FreeFunctionPtr)GetProcAddress(NtDllHandle, "RtlFreeHeap");
27 if (RtlFreeHeap_ptr == 0) {
28 puts("Couldn't RtlFreeHeap");
29 return -1;
32 char *winbuf;
33 char *asanbuf;
34 winbuf = (char *)RtlAllocateHeap_ptr(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, 32),
35 asanbuf = (char *)RtlAllocateHeap_ptr(GetProcessHeap(), 0, 32),
36 winbuf[0] = 'a';
37 assert(!__sanitizer_get_ownership(winbuf));
38 assert(__sanitizer_get_ownership(asanbuf));
40 RtlFreeHeap_ptr(GetProcessHeap(), 0, winbuf);
41 RtlFreeHeap_ptr(GetProcessHeap(), 0, asanbuf);
42 puts("Okay");
43 // CHECK: Okay