blob: ee3d59c721722d2d6682287b0fc70f472bb6eee2 [file] [log] [blame]
Stephen Hines86277eb2015-03-23 12:06:32 -07001// RUN: %clangxx -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
2// Check __sanitizer_set_death_callback. Not all sanitizers implement it yet.
3// XFAIL: lsan
4// XFAIL: tsan
5
6#include <sanitizer/common_interface_defs.h>
7#include <stdio.h>
8#include <pthread.h>
9
10volatile char *zero = 0;
11
12void Death() {
13 fprintf(stderr, "DEATH CALLBACK EXECUTED\n");
14}
15// CHECK: DEATH CALLBACK EXECUTED
16
17int global[10];
18volatile char *sink;
19
20void *Thread(void *x) {
21 global[0]++;
22 return x;
23}
24
25__attribute__((noinline))
26void MaybeInit(int *uninitialized) {
27 if (zero)
28 *uninitialized = 1;
29}
30
31__attribute__((noinline))
32void Leak() {
33 sink = new char[100]; // trigger lsan report.
34}
35
36int main(int argc, char **argv) {
37 int uninitialized;
38 __sanitizer_set_death_callback(Death);
39 MaybeInit(&uninitialized);
40 if (uninitialized) // trigger msan report.
41 global[0] = 77;
42 pthread_t t;
43 pthread_create(&t, 0, Thread, 0);
44 global[0]++; // trigger tsan report.
45 pthread_join(t, 0);
46 global[argc + 10]++; // trigger asan report.
47 Leak();
48 sink = 0;
49}