1// RUN: %clangxx_asan -O0 %s -o %t
2// RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
3// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
4
5// RUN: %clangxx_asan -O0 %s -o %t -DUSER_FUNCTION
6// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH
7
8// It is expected that ASAN_OPTS will override the value set through the user function.
9// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUCCESS
10
11#if USER_FUNCTION
12// It's important to test the `alloc_dealloc_mismatch` flag set through the user function because, on Windows,
13// flags configured through the user-defined function `__asan_default_options` are not always be honored.
14// See: https://github.com/llvm/llvm-project/issues/117925
15extern "C" __declspec(dllexport) extern const char *__asan_default_options() {
16 return "alloc_dealloc_mismatch=1";
17}
18#endif
19
20#include <cstdio>
21#include <cstdlib>
22
23// Tests the `alloc_dealloc_mismatch` flag set both via user function and through the environment variable.
24int main() {
25 // In the 'CHECK-MISMATCH' case, we simply check that the AddressSanitizer reports an error.
26 delete (new int[10]); // CHECK-MISMATCH: AddressSanitizer:
27 printf(format: "Success"); // CHECK-SUCCESS: Success
28 return 0;
29}

source code of compiler-rt/test/asan/TestCases/Windows/alloc_dealloc_mismatch.cpp