blob: ad6e09279b3dcdc1ed0d36f9386482ecd3038c7e [file] [log] [blame]
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -07001// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
2// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe
Stephen Hines86277eb2015-03-23 12:06:32 -07003
4// Check that without suppressions, we catch the issue.
5// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
6
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08007// FIXME: Remove usage of backticks around basename below.
8// REQUIRES: shell
9
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070010// RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080011// RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
Stephen Hines86277eb2015-03-23 12:06:32 -070012
13// XFAIL: android
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
19#if !defined(SHARED_LIB)
20
21void crash_function();
22
23int main(int argc, char *argv[]) {
24 crash_function();
25 return 0;
26}
27
28#else // SHARED_LIB
29
30void crash_function() {
31 char *a = (char *)malloc(6);
32 free(a);
33 size_t len = strlen(a); // BOOM
34 fprintf(stderr, "strlen ignored, %zu\n", len);
35}
36
37#endif // SHARED_LIB
38
39// CHECK-CRASH: AddressSanitizer: heap-use-after-free
40// CHECK-CRASH-NOT: strlen ignored
41// CHECK-IGNORE-NOT: AddressSanitizer: heap-use-after-free
42// CHECK-IGNORE: strlen ignored