aboutsummaryrefslogtreecommitdiff
path: root/lib/asan/lit_tests/use-after-poison.cc
blob: d87342900245ea047338ae8493ec88d747bee53d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Check that __asan_poison_memory_region works.
// RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
//
// Check that we can disable it
// RUN: ASAN_OPTIONS=allow_user_poisoning=0 %t

#include <stdlib.h>

extern "C" void __asan_poison_memory_region(void *, size_t);

int main(int argc, char **argv) {
  char *x = new char[16];
  x[10] = 0;
  __asan_poison_memory_region(x, 16);
  int res = x[argc * 10];  // BOOOM
  // CHECK: ERROR: AddressSanitizer: use-after-poison
  // CHECK: main{{.*}}use-after-poison.cc:[[@LINE-2]]
  delete [] x;
  return res;
}