Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_asan -O2 %s -o %t |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 2 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST |
| 3 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 available on x86_64 and i386. |
| 10 | // REQUIRES: x86_64-supported-target |
| 11 | |
| 12 | // REQUIRES: compiler-rt-optimized |
| 13 | |
| 14 | #include <stdlib.h> |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | int *GlobalPtr; |
| 18 | |
| 19 | extern "C" { |
| 20 | int QsortCallback(const void *a, const void *b) { |
| 21 | char *x = (char*)a; |
| 22 | char *y = (char*)b; |
| 23 | printf("Calling QsortCallback\n"); |
| 24 | GlobalPtr = new int[10]; |
| 25 | return (int)*x - (int)*y; |
| 26 | } |
| 27 | |
| 28 | __attribute__((noinline)) |
| 29 | void MyQsort(char *a, size_t size) { |
| 30 | printf("Calling qsort\n"); |
| 31 | qsort(a, size, sizeof(char), QsortCallback); |
| 32 | printf("Done\n"); // Avoid tail call. |
| 33 | } |
| 34 | } // extern "C" |
| 35 | |
| 36 | int main() { |
| 37 | char a[2] = {1, 2}; |
| 38 | MyQsort(a, 2); |
| 39 | return GlobalPtr[10]; |
| 40 | } |
| 41 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 42 | // Fast unwind may not unwind through qsort. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 47 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 48 | // CHECK-SLOW: ERROR: AddressSanitizer: heap-buffer-overflow |
| 49 | // CHECK-SLOW: is located 0 bytes to the right |
| 50 | // CHECK-SLOW: #0{{.*}}operator new |
| 51 | // CHECK-SLOW-NEXT: #1{{.*}}QsortCallback |
| 52 | // CHECK-SLOW: #{{.*}}MyQsort |
| 53 | // CHECK-SLOW-NEXT: #{{.*}}main |