| 1 | // Sanitizer should not crash if pthread_create fails. |
|---|---|
| 2 | // RUN: %clangxx -pthread %s -o %t && %run %t |
| 3 | |
| 4 | // pthread_create with lsan i386 does not fail here. |
| 5 | // UNSUPPORTED: i386-linux && lsan |
| 6 | |
| 7 | #include <cassert> |
| 8 | #include <pthread.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | void *null_func(void *args) { |
| 12 | return NULL; |
| 13 | } |
| 14 | |
| 15 | int main(void) { |
| 16 | pthread_t thread; |
| 17 | pthread_attr_t attrs; |
| 18 | pthread_attr_init(attr: &attrs); |
| 19 | // Set size huge enough to fail pthread_create. |
| 20 | size_t sz = ~0; |
| 21 | // Align the size just in case. |
| 22 | sz >>= 16; |
| 23 | sz <<= 16; |
| 24 | int res = pthread_attr_setstacksize(attr: &attrs, stacksize: sz); |
| 25 | assert(res == 0); |
| 26 | for (size_t i = 0; i < 10; ++i) { |
| 27 | res = pthread_create(newthread: &thread, attr: &attrs, start_routine: null_func, NULL); |
| 28 | assert(res != 0); |
| 29 | } |
| 30 | return 0; |
| 31 | } |
| 32 |
