[compiler-rt] 269aa74 - tsan: add another use-after-free race test
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 25 05:06:59 PDT 2021
Author: Dmitry Vyukov
Date: 2021-10-25T14:06:55+02:00
New Revision: 269aa74aed43780b88f32f89f7407da539da15d5
URL: https://github.com/llvm/llvm-project/commit/269aa74aed43780b88f32f89f7407da539da15d5
DIFF: https://github.com/llvm/llvm-project/commit/269aa74aed43780b88f32f89f7407da539da15d5.diff
LOG: 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
Added:
compiler-rt/test/tsan/free_race3.c
Modified:
Removed:
################################################################################
diff --git a/compiler-rt/test/tsan/free_race3.c b/compiler-rt/test/tsan/free_race3.c
new file mode 100644
index 0000000000000..55efd6e121348
--- /dev/null
+++ b/compiler-rt/test/tsan/free_race3.c
@@ -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
More information about the llvm-commits
mailing list