brintos

brintos / llvm-project-archived public Read only

0
0
Text · 725 B · 8ed9b4c Raw
32 lines · cpp
1// Sanitizer should not crash if pthread_create fails.2// RUN: %clangxx -pthread %s -o %t && %run %t3 4// pthread_create with lsan i386 does not fail here.5// UNSUPPORTED: i386-linux && lsan6 7#include <cassert>8#include <pthread.h>9#include <stdlib.h>10 11void *null_func(void *args) {12  return NULL;13}14 15int main(void) {16  pthread_t thread;17  pthread_attr_t attrs;18  pthread_attr_init(&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(&attrs, sz);25  assert(res == 0);26  for (size_t i = 0; i < 10; ++i) {27    res = pthread_create(&thread, &attrs, null_func, NULL);28    assert(res != 0);29  }30  return 0;31}32