brintos

brintos / llvm-project-archived public Read only

0
0
Text · 964 B · 98fe610 Raw
36 lines · cpp
1// Ensure that operator new/delete are still replaceable using static-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// darwin only supports `shared-libsan`.9// REQUIRES: asan-static-runtime10 11// RUN: %clangxx %s -o %t -fsanitize=address -static-libsan && not %run %t 2>&1 | FileCheck %s12 13#include <cstdio>14#include <cstdlib>15#include <new>16 17void *operator new[](size_t size) {18  fprintf(stderr, "replaced new\n");19  return malloc(size);20}21 22void operator delete[](void *ptr) noexcept {23  fprintf(stderr, "replaced delete\n");24  return free(ptr);25}26 27int main(int argc, char **argv) {28  // CHECK: replaced new29  char *x = new char[5];30  // CHECK: replaced delete31  delete[] x;32  // CHECK: ERROR: AddressSanitizer33  *x = 13;34  return 0;35}36