1 // { dg-do run { target pthread } }
2 // { dg-options "-lasan -lpthread" }
3 // { dg-shouldfail "asan" }
9 void *AllocThread(void *arg) {
15 void *FreeThread(void *arg) {
20 void *AccessThread(void *arg) {
25 typedef void* (*callback_type)(void* arg);
27 void *RunnerThread(void *function) {
29 pthread_create(&thread, NULL, (callback_type)function, NULL);
30 pthread_join(thread, NULL);
34 void RunThread(callback_type function) {
36 pthread_create(&runner, NULL, RunnerThread, (void*)function);
37 pthread_join(runner, NULL);
40 int main(int argc, char *argv[]) {
41 RunThread(AllocThread);
42 RunThread(FreeThread);
43 RunThread(AccessThread);
47 // { dg-output "ERROR: AddressSanitizer: heap-use-after-free.*(\n|\r\n|\r)" }
48 // { dg-output "\[^\n\r]*WRITE of size 4 at 0x\[0-9a-f\]+ thread T(\[0-9\]+).*(\n|\r\n|\r)" }
49 // { dg-output "\[^\n\r]*freed by thread T(\[0-9\]+) here:.*(\n|\r\n|\r)" }
50 // { dg-output "\[^\n\r]*previously allocated by thread T(\[0-9\]+) here:.*(\n|\r\n|\r)" }
51 // { dg-output "Thread T\\2 created by T(\[0-9\]+) here:.*(\n|\r\n|\r)" }
52 // { dg-output "Thread T\\8 created by T0 here:.*(\n|\r\n|\r)" }
53 // { dg-output "Thread T\\4 created by T(\[0-9\]+) here:.*(\n|\r\n|\r)" }
54 // { dg-output "Thread T\\11 created by T0 here:.*(\n|\r\n|\r)" }
55 // { dg-output "Thread T\\6 created by T(\[0-9\]+) here:.*(\n|\r\n|\r)" }
56 // { dg-output "Thread T\\14 created by T0 here:" }