Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / poison_in_signal.cpp
blob5e833e516db964a94a0341d431cb0ab16b6b2447
1 // Stress test of poisoning from signal handler.
3 // RUN: %clangxx_msan -std=c++11 -O2 %s -o %t && %run %t
4 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -std=c++11 -O2 %s -o %t && %run %t
5 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -fsanitize-memory-use-after-dtor -std=c++11 -O2 %s -o %t && %run %t
7 #include <assert.h>
8 #include <atomic>
9 #include <pthread.h>
10 #include <signal.h>
11 #include <sys/time.h>
13 #include <sanitizer/msan_interface.h>
15 std::atomic<int> n = {1000};
17 struct Tmp {
18 char buff[1];
19 ~Tmp() {}
22 __attribute__((noinline, optnone)) void Poison() {
23 // use-after-dtor.
24 volatile Tmp t;
25 // Regular poisoning.
26 __msan_poison(&t, sizeof(t));
29 void *thr(void *p) {
30 for (; n >= 0;) {
31 for (int i = 0; i < 1000; i++) {
32 Poison();
35 return 0;
38 void handler(int) {
39 Poison();
40 --n;
43 int main(int argc, char **argv) {
44 const int kThreads = 10;
45 pthread_t th[kThreads];
46 for (int i = 0; i < kThreads; i++)
47 pthread_create(&th[i], 0, thr, 0);
49 struct sigaction sa = {};
50 sa.sa_handler = handler;
51 assert(!sigaction(SIGPROF, &sa, 0));
53 itimerval t;
54 t.it_value.tv_sec = 0;
55 t.it_value.tv_usec = 10;
56 t.it_interval = t.it_value;
57 assert(!setitimer(ITIMER_PROF, &t, 0));
59 for (int i = 0; i < kThreads; i++)
60 pthread_join(th[i], 0);
62 return 0;