Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Check that we detect malloc/delete mismatch only if the approptiate flag |
| 2 | // is set. |
| 3 | |
| 4 | // RUN: %clangxx_asan -g %s -o %t 2>&1 |
| 5 | |
| 6 | // Find error and provide malloc context. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 7 | // RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | |
| 9 | // No error here. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 10 | // RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | |
| 12 | // Also works if no malloc context is available. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 13 | // RUN: %env_asan_opts=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s |
| 14 | // RUN: %env_asan_opts=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 15 | // XFAIL: arm-linux-gnueabi |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 16 | // XFAIL: armv7l-unknown-linux-gnueabihf |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | |
| 19 | static volatile char *x; |
| 20 | |
| 21 | int main() { |
| 22 | x = (char*)malloc(10); |
| 23 | x[0] = 0; |
| 24 | delete x; |
| 25 | } |
| 26 | // CHECK: ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x |
| 27 | // CHECK-NEXT: #0{{.*}}operator delete |
| 28 | // CHECK: #{{.*}}main |
| 29 | // CHECK: is located 0 bytes inside of 10-byte region |
| 30 | // CHECK-NEXT: allocated by thread T0 here: |
| 31 | // ALLOC-STACK-NEXT: #0{{.*}}malloc |
| 32 | // ALLOC-STACK: #{{.*}}main |
| 33 | // CHECK: HINT: {{.*}} you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0 |