use-after-free.cc revision 6a211c5814e25d6745a5058cc0e499e5235d3821
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// XFAIL: arm-linux-gnueabi 6 7#include <stdlib.h> 8int main() { 9 char *x = (char*)malloc(10 * sizeof(char)); 10 free(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-free.cc:}}[[@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 .*free}} 20 // CHECK-Linux: {{ #1 0x.* in main .*use-after-free.cc:}}[[@LINE-10]] 21 22 // CHECK-Darwin: {{ #0 0x.* in wrap_free}} 23 // CHECK-Darwin: {{ #1 0x.* in main .*use-after-free.cc:}}[[@LINE-13]] 24 25 // CHECK: {{previously allocated by thread T0 here:}} 26 27 // CHECK-Linux: {{ #0 0x.* in .*malloc}} 28 // CHECK-Linux: {{ #1 0x.* in main .*use-after-free.cc:}}[[@LINE-19]] 29 30 // CHECK-Darwin: {{ #0 0x.* in wrap_malloc.*}} 31 // CHECK-Darwin: {{ #1 0x.* in main .*use-after-free.cc:}}[[@LINE-22]] 32 // CHECK: Shadow byte legend (one shadow byte represents 8 application bytes): 33 // CHECK: Global redzone: 34 // CHECK: ASan internal: 35} 36