2015-06-16 05:08:47 +08:00
|
|
|
// RUN: %clang_safestack %s -pthread -o %t
|
2018-08-10 08:36:04 +08:00
|
|
|
// RUN: not --crash %run %t
|
2015-06-16 05:08:47 +08:00
|
|
|
|
2018-08-10 08:36:04 +08:00
|
|
|
// Test that unsafe stacks are deallocated correctly on thread exit.
|
2015-06-16 05:08:47 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
enum { kBufferSize = (1 << 15) };
|
|
|
|
|
2018-08-10 08:36:04 +08:00
|
|
|
void *t1_start(void *ptr)
|
2015-06-16 05:08:47 +08:00
|
|
|
{
|
|
|
|
char buffer[kBufferSize];
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2018-08-10 08:36:04 +08:00
|
|
|
pthread_t t1;
|
|
|
|
char *buffer = NULL;
|
2015-06-16 05:08:47 +08:00
|
|
|
|
2018-08-10 08:36:04 +08:00
|
|
|
if (pthread_create(&t1, NULL, t1_start, NULL))
|
2015-06-16 05:08:47 +08:00
|
|
|
abort();
|
2018-08-10 08:36:04 +08:00
|
|
|
if (pthread_join(t1, &buffer))
|
2015-06-16 05:08:47 +08:00
|
|
|
abort();
|
|
|
|
|
|
|
|
// should segfault here
|
2018-08-10 08:36:04 +08:00
|
|
|
memset(buffer, 0, kBufferSize);
|
2015-06-16 05:08:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|