• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out
2 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
3 // RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out
4 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
5 // RUN: %clangxx_asan -m64 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out
6 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
7 // RUN: %clangxx_asan -m64 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out
8 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
9 // RUN: %clangxx_asan -m32 -O0 %s -o %t && %t 2>&1 | %symbolize > %t.out
10 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
11 // RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 | %symbolize > %t.out
12 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
13 // RUN: %clangxx_asan -m32 -O2 %s -o %t && %t 2>&1 | %symbolize > %t.out
14 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
15 // RUN: %clangxx_asan -m32 -O3 %s -o %t && %t 2>&1 | %symbolize > %t.out
16 // RUN: FileCheck %s < %t.out && FileCheck %s --check-prefix=CHECK-%os < %t.out
17 
18 #include <stdlib.h>
main()19 int main() {
20   char *x = (char*)malloc(10 * sizeof(char));
21   free(x);
22   return x[5];
23   // CHECK: {{.*ERROR: AddressSanitizer heap-use-after-free on address}}
24   // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
25   // CHECK: {{READ of size 1 at 0x.* thread T0}}
26   // CHECK: {{    #0 0x.* in main .*use-after-free.cc:22}}
27   // CHECK: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
28   // CHECK: {{freed by thread T0 here:}}
29 
30   // CHECK-Linux: {{    #0 0x.* in .*free}}
31   // CHECK-Linux: {{    #1 0x.* in main .*use-after-free.cc:21}}
32 
33   // CHECK-Darwin: {{    #0 0x.* in .*mz_free.*}}
34   // We override free() on Darwin, thus no malloc_zone_free
35   // CHECK-Darwin: {{    #1 0x.* in wrap_free}}
36   // CHECK-Darwin: {{    #2 0x.* in main .*use-after-free.cc:21}}
37 
38   // CHECK: {{previously allocated by thread T0 here:}}
39 
40   // CHECK-Linux: {{    #0 0x.* in .*malloc}}
41   // CHECK-Linux: {{    #1 0x.* in main .*use-after-free.cc:20}}
42 
43   // CHECK-Darwin: {{    #0 0x.* in .*mz_malloc.*}}
44   // CHECK-Darwin: {{    #1 0x.* in malloc_zone_malloc.*}}
45   // CHECK-Darwin: {{    #2 0x.* in malloc.*}}
46   // CHECK-Darwin: {{    #3 0x.* in main .*use-after-free.cc:20}}
47 }
48