• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
2 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
3 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
4 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
5 // REQUIRES: stable-runtime
6 
7 #include <stdlib.h>
main()8 int main() {
9   char * volatile x = new char[10];
10   delete[] x;
11   return x[5];
12   // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
13   // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
14   // CHECK: {{READ of size 1 at 0x.* thread T0}}
15   // CHECK: {{    #0 0x.* in main .*use-after-delete.cpp:}}[[@LINE-4]]
16   // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
17   // CHECK: {{freed by thread T0 here:}}
18 
19   // CHECK-Linux: {{    #0 0x.* in operator delete\[\]}}
20   // CHECK-Linux: {{    #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-10]]
21 
22   // CHECK: {{previously allocated by thread T0 here:}}
23 
24   // CHECK-Linux: {{    #0 0x.* in operator new\[\]}}
25   // CHECK-Linux: {{    #1 0x.* in main .*use-after-delete.cpp:}}[[@LINE-16]]
26 
27   // CHECK: Shadow byte legend (one shadow byte represents {{[0-9]+}} application bytes):
28   // CHECK: Global redzone:
29   // CHECK: ASan internal:
30 }
31