1// Check that without suppressions, we catch the issue.
2// RUN: %clangxx_asan -O0 %s -o %t
3// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
4
5// RUN: echo "interceptor_via_fun:crash_function" > %t.supp
6// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
7// RUN: %clangxx_asan -O3 %s -o %t && %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
8
9// XFAIL: android
10// UNSUPPORTED: ios
11
12// FIXME: atos does not work for inlined functions, yet llvm-symbolizer
13// does not always work with debug info on Darwin.
14// UNSUPPORTED: darwin
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20void crash_function() {
21 char *a = (char *)malloc(size: 6);
22 free(ptr: a);
23 size_t len = strlen(s: a); // BOOM
24 fprintf(stderr, format: "strlen ignored, len = %zu\n", len);
25}
26
27int main() {
28 crash_function();
29}
30
31// CHECK-CRASH: AddressSanitizer: heap-use-after-free
32// CHECK-CRASH-NOT: strlen ignored
33// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
34// CHECK-IGNORE: strlen ignored
35

source code of compiler-rt/test/asan/TestCases/suppressions-function.cpp