1 | // Check that without suppressions, we catch the issue. |
2 | // RUN: %clangxx_asan -O0 %s -o %t |
3 | // RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s |
4 | |
5 | // RUN: echo "alloc_dealloc_mismatch:function" > %t.supp |
6 | // RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1:suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
7 | // RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1:suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s |
8 | |
9 | // FIXME: Upload suppressions to device. |
10 | // XFAIL: android |
11 | |
12 | // FIXME: atos does not work for inlined functions, yet llvm-symbolizer |
13 | // does not always work with debug info on Darwin. Behavior is similar on MSVC x86 outside of /Od. |
14 | // UNSUPPORTED: darwin |
15 | // UNSUPPORTED: target={{.*windows-msvc.*}} && asan-32-bits |
16 | |
17 | #include <stdio.h> |
18 | #include <stdlib.h> |
19 | #include <string.h> |
20 | |
21 | void function() { |
22 | char *a = (char *)malloc(size: 6); |
23 | a[0] = '\0'; |
24 | size_t len = strlen(s: a); |
25 | delete a; // BOOM |
26 | fprintf(stderr, format: "strlen ignored, len = %zu\n" , len); |
27 | } |
28 | |
29 | int main() { function(); } |
30 | |
31 | // CHECK-CRASH: AddressSanitizer: alloc-dealloc-mismatch |
32 | // CHECK-CRASH-NOT: strlen ignored |
33 | // CHECK-IGNORE-NOT: AddressSanitizer: alloc-dealloc-mismatch |
34 | // CHECK-IGNORE: strlen ignored |
35 | |