Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / replaceable_new_delete_shared.cpp
blob6a78ebb3489b99620123e4360952820a76437db5
1 // Ensure that operator new/delete are still replaceable using shared-libsan.
3 // FIXME: Weak symbols aren't supported on Windows, although some code in
4 // compiler-rt already exists to solve this problem. We should probably define
5 // the new/delete interceptors as "weak" using those workarounds as well.
6 // UNSUPPORTED: target={{.*windows.*}}
8 // RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s
10 #include <cstdio>
11 #include <cstdlib>
12 #include <new>
14 void *operator new[](size_t size) {
15 fprintf(stderr, "replaced new\n");
16 return malloc(size);
19 void operator delete[](void *ptr) noexcept {
20 fprintf(stderr, "replaced delete\n");
21 return free(ptr);
24 int main(int argc, char **argv) {
25 // CHECK: replaced new
26 char *x = new char[5];
27 // CHECK: replaced delete
28 delete[] x;
29 // CHECK: ERROR: AddressSanitizer
30 *x = 13;
31 return 0;