Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | // 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 | |
| 10 | volatile char *zero = 0; |
| 11 | |
| 12 | void Death() { |
| 13 | fprintf(stderr, "DEATH CALLBACK EXECUTED\n"); |
| 14 | } |
| 15 | // CHECK: DEATH CALLBACK EXECUTED |
| 16 | |
| 17 | int global[10]; |
| 18 | volatile char *sink; |
| 19 | |
| 20 | void *Thread(void *x) { |
| 21 | global[0]++; |
| 22 | return x; |
| 23 | } |
| 24 | |
| 25 | __attribute__((noinline)) |
| 26 | void MaybeInit(int *uninitialized) { |
| 27 | if (zero) |
| 28 | *uninitialized = 1; |
| 29 | } |
| 30 | |
| 31 | __attribute__((noinline)) |
| 32 | void Leak() { |
| 33 | sink = new char[100]; // trigger lsan report. |
| 34 | } |
| 35 | |
| 36 | int 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 | } |