1fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// Check that we detect malloc/delete mismatch only if the approptiate flag 2fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// is set. 3fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany 4fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// RUN: %clangxx_asan -g %s -o %t 2>&1 51b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov 61b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov// Find error and provide malloc context. 72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK 8fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany 9fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// No error here. 102d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=0 %run %t 111b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov 121b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov// Also works if no malloc context is available. 132d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s 142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s 155d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines// XFAIL: arm-linux-gnueabi 16fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany#include <stdlib.h> 17fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany 18fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryanystatic volatile char *x; 19fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany 20fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryanyint main() { 21fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany x = (char*)malloc(10); 22fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany x[0] = 0; 23fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany delete x; 24fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany} 25fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// CHECK: ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x 26fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// CHECK-NEXT: #0{{.*}}operator delete 2742383abd153b1843fa2695542065fa956ebb41adKostya Serebryany// CHECK: #{{.*}}main 28fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// CHECK: is located 0 bytes inside of 10-byte region 29fe6d91684bcda766593800f6307233f1a33d31f6Kostya Serebryany// CHECK-NEXT: allocated by thread T0 here: 301b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov// ALLOC-STACK-NEXT: #0{{.*}}malloc 311b17f5b79d58c5aff291dde05727ad0b215b81c6Alexey Samsonov// ALLOC-STACK: #{{.*}}main 3203ef193f5310f62989285d88cd0e54e05f927769Alexander Potapenko// CHECK: HINT: {{.*}} you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0 33