• 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 // Test use-after-free report in the case when access is at the right border of
19 //  the allocation.
20 
21 #include <stdlib.h>
main()22 int main() {
23   volatile char *x = (char*)malloc(sizeof(char));
24   free((void*)x);
25   *x = 42;
26   // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
27   // CHECK:   {{0x.* at pc 0x.* bp 0x.* sp 0x.*}}
28   // CHECK: {{WRITE of size 1 at 0x.* thread T0}}
29   // CHECK: {{    #0 0x.* in _?main .*use-after-free-right.cc:25}}
30   // CHECK: {{0x.* is located 0 bytes inside of 1-byte region .0x.*,0x.*}}
31   // CHECK: {{freed by thread T0 here:}}
32 
33   // CHECK-Linux: {{    #0 0x.* in .*free}}
34   // CHECK-Linux: {{    #1 0x.* in main .*use-after-free-right.cc:24}}
35 
36   // CHECK-Darwin: {{    #0 0x.* in _?wrap_free}}
37   // CHECK-Darwin: {{    #1 0x.* in _?main .*use-after-free-right.cc:24}}
38 
39   // CHECK: {{previously allocated by thread T0 here:}}
40 
41   // CHECK-Linux: {{    #0 0x.* in .*malloc}}
42   // CHECK-Linux: {{    #1 0x.* in main .*use-after-free-right.cc:23}}
43 
44   // CHECK-Darwin: {{    #0 0x.* in _?wrap_malloc.*}}
45   // CHECK-Darwin: {{    #1 0x.* in _?main .*use-after-free-right.cc:23}}
46 }
47