brintos

brintos / llvm-project-archived public Read only

0
0
Text · 889 B · 6a78ebb Raw
33 lines · cpp
1// Ensure that operator new/delete are still replaceable using shared-libsan.2 3// FIXME: Weak symbols aren't supported on Windows, although some code in4// compiler-rt already exists to solve this problem. We should probably define5// the new/delete interceptors as "weak" using those workarounds as well.6// UNSUPPORTED: target={{.*windows.*}}7 8// RUN: %clangxx %s -o %t -fsanitize=address -shared-libsan && not %run %t 2>&1 | FileCheck %s9 10#include <cstdio>11#include <cstdlib>12#include <new>13 14void *operator new[](size_t size) {15  fprintf(stderr, "replaced new\n");16  return malloc(size);17}18 19void operator delete[](void *ptr) noexcept {20  fprintf(stderr, "replaced delete\n");21  return free(ptr);22}23 24int main(int argc, char **argv) {25  // CHECK: replaced new26  char *x = new char[5];27  // CHECK: replaced delete28  delete[] x;29  // CHECK: ERROR: AddressSanitizer30  *x = 13;31  return 0;32}33