1 // RUN: %clangxx_asan -O2 %s -o %t 2 // RUN: ASAN_OPTIONS=fast_unwind_on_malloc=1 not %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST 3 // RUN: ASAN_OPTIONS=fast_unwind_on_malloc=0 not %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW 4 5 // Test how well we unwind in presence of qsort in the stack 6 // (i.e. if we can unwind through a function compiled w/o frame pointers). 7 // https://code.google.com/p/address-sanitizer/issues/detail?id=137 8 9 // Fast unwinder is only avaliable on x86_64 and i386. 10 // REQUIRES: x86_64-supported-target 11 12 #include <stdlib.h> 13 #include <stdio.h> 14 15 int *GlobalPtr; 16 17 extern "C" { 18 int QsortCallback(const void *a, const void *b) { 19 char *x = (char*)a; 20 char *y = (char*)b; 21 printf("Calling QsortCallback\n"); 22 GlobalPtr = new int[10]; 23 return (int)*x - (int)*y; 24 } 25 26 __attribute__((noinline)) 27 void MyQsort(char *a, size_t size) { 28 printf("Calling qsort\n"); 29 qsort(a, size, sizeof(char), QsortCallback); 30 printf("Done\n"); // Avoid tail call. 31 } 32 } // extern "C" 33 34 int main() { 35 char a[2] = {1, 2}; 36 MyQsort(a, 2); 37 return GlobalPtr[10]; 38 } 39 40 // Fast unwind: can not unwind through qsort. 41 // FIXME: this test does not properly work with slow unwind yet. 42 43 // CHECK-FAST: ERROR: AddressSanitizer: heap-buffer-overflow 44 // CHECK-FAST: is located 0 bytes to the right 45 // CHECK-FAST: #0{{.*}}operator new 46 // CHECK-FAST-NEXT: #1{{.*}}QsortCallback 47 // CHECK-FAST-NOT: MyQsort 48 // 49 // CHECK-SLOW: ERROR: AddressSanitizer: heap-buffer-overflow 50 // CHECK-SLOW: is located 0 bytes to the right 51 // CHECK-SLOW: #0{{.*}}operator new 52 // CHECK-SLOW-NEXT: #1{{.*}}QsortCallback 53 // CHECK-SLOW: #{{.*}}MyQsort 54 // CHECK-SLOW-NEXT: #{{.*}}main 55