Peter Collingbourne | b64d0b1 | 2015-06-15 21:08:47 +0000 | [diff] [blame] | 1 | // RUN: %clang_safestack %s -pthread -o %t |
| 2 | // RUN: not --crash %run %t |
| 3 | |
| 4 | // Test that unsafe stacks are deallocated correctly on thread exit. |
| 5 | |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <pthread.h> |
| 9 | |
| 10 | enum { kBufferSize = (1 << 15) }; |
| 11 | |
| 12 | void *t1_start(void *ptr) |
| 13 | { |
| 14 | char buffer[kBufferSize]; |
| 15 | return buffer; |
| 16 | } |
| 17 | |
| 18 | int main(int argc, char **argv) |
| 19 | { |
| 20 | pthread_t t1; |
| 21 | char *buffer = NULL; |
| 22 | |
| 23 | if (pthread_create(&t1, NULL, t1_start, NULL)) |
| 24 | abort(); |
| 25 | if (pthread_join(t1, &buffer)) |
| 26 | abort(); |
| 27 | |
| 28 | // should segfault here |
| 29 | memset(buffer, 0, kBufferSize); |
| 30 | return 0; |
| 31 | } |