[compiler-rt] r177996 - [tsan] add a test for aligned-vs-unaligned race (tsan's false negative)

Kostya Serebryany kcc at google.com
Tue Mar 26 01:31:02 PDT 2013


Author: kcc
Date: Tue Mar 26 03:31:02 2013
New Revision: 177996

URL: http://llvm.org/viewvc/llvm-project?rev=177996&view=rev
Log:
[tsan] add a test for aligned-vs-unaligned race (tsan's false negative)

Added:
    compiler-rt/trunk/lib/tsan/lit_tests/aligned_vs_unaligned_race.cc

Added: compiler-rt/trunk/lib/tsan/lit_tests/aligned_vs_unaligned_race.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/aligned_vs_unaligned_race.cc?rev=177996&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/aligned_vs_unaligned_race.cc (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/aligned_vs_unaligned_race.cc Tue Mar 26 03:31:02 2013
@@ -0,0 +1,30 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %t
+// Race between an aligned access and an unaligned access, which
+// touches the same memory region.
+// This is a real race which is not detected by tsan.
+// https://code.google.com/p/thread-sanitizer/issues/detail?id=17
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+
+uint64_t Global[2];
+
+void *Thread1(void *x) {
+  Global[1]++;
+  return NULL;
+}
+
+void *Thread2(void *x) {
+  char *p1 = reinterpret_cast<char *>(&Global[0]);
+  uint64_t *p4 = reinterpret_cast<uint64_t *>(p1 + 1);
+  (*p4)++;
+  return NULL;
+}
+
+int main() {
+  pthread_t t[2];
+  pthread_create(&t[0], NULL, Thread1, NULL);
+  pthread_create(&t[1], NULL, Thread2, NULL);
+  pthread_join(t[0], NULL);
+  pthread_join(t[1], NULL);
+}





More information about the llvm-commits mailing list