Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / safestack / pthread.c
blob1687c10a6ef2e83b60f33958e5b507da2dfb81fd
1 // RUN: %clang_safestack %s -pthread -o %t
2 // RUN: %run %t
4 // Test that pthreads receive their own unsafe stack.
6 #include <stdlib.h>
7 #include <string.h>
8 #include <pthread.h>
9 #include "utils.h"
11 static int ptr_test = 42;
13 void *t1_start(void *ptr)
15 if (ptr != &ptr_test)
16 abort();
18 // safe stack
19 int val = ptr_test * 5;
21 // unsafe stack
22 char buffer[8096]; // two pages
23 memset(buffer, val, sizeof (buffer));
24 break_optimization(buffer);
26 return ptr;
29 int main(int argc, char **argv)
31 pthread_t t1;
32 void *ptr = NULL;
33 if (pthread_create(&t1, NULL, t1_start, &ptr_test))
34 abort();
35 if (pthread_join(t1, &ptr))
36 abort();
37 if (ptr != &ptr_test)
38 abort();
39 return 0;