blob: fe5419f17938812e17c144635b31f307a1a0d157 [file] [log] [blame]
Stephen Hines86277eb2015-03-23 12:06:32 -07001// 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
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07006// RUN: %clangxx_asan -O0 %s -o %t && ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
7// RUN: %clangxx_asan -O3 %s -o %t && ASAN_OPTIONS="$ASAN_OPTIONS:suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
Stephen Hines86277eb2015-03-23 12:06:32 -07008
9// XFAIL: android
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15void crash_function() {
16 char *a = (char *)malloc(6);
17 free(a);
18 size_t len = strlen(a); // BOOM
19 fprintf(stderr, "strlen ignored, len = %zu\n", len);
20}
21
22int main() {
23 crash_function();
24}
25
26// CHECK-CRASH: AddressSanitizer: heap-use-after-free
27// CHECK-CRASH-NOT: strlen ignored
28// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
29// CHECK-IGNORE: strlen ignored