tsan: add another use-after-free race test

Add a test where a race with free is called during the free itself
(we only have tests where a race with free is caught during the other memory acces).

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112433
This commit is contained in:
Dmitry Vyukov 2021-10-24 14:19:16 +02:00
parent 75a08b1ba4
commit 269aa74aed
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "test.h"
int *mem;
void *Thread(void *x) {
mem[0] = 42;
barrier_wait(&barrier);
return NULL;
}
int main() {
barrier_init(&barrier, 2);
mem = (int*)malloc(100);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
barrier_wait(&barrier);
free(mem);
pthread_join(t, NULL);
return 0;
}
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 8 at {{.*}} by main thread{{.*}}:
// CHECK: #0 free
// CHECK: #1 main
// CHECK: Previous write of size 4 at {{.*}} by thread T1{{.*}}:
// CHECK: #0 Thread