From 95f3e54066f3e9b92b0e98de32b9a4b05714af01 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Thu, 21 Nov 2013 07:31:12 +0000 Subject: [PATCH] [tsan] add a run-time-side regression test for https://code.google.com/p/thread-sanitizer/issues/detail?id=40 (tsan-hostile load speculation) llvm-svn: 195325 --- .../lit_tests/race_on_speculative_load.cc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 compiler-rt/lib/tsan/lit_tests/race_on_speculative_load.cc diff --git a/compiler-rt/lib/tsan/lit_tests/race_on_speculative_load.cc b/compiler-rt/lib/tsan/lit_tests/race_on_speculative_load.cc new file mode 100644 index 000000000000..0c7dbb568ab2 --- /dev/null +++ b/compiler-rt/lib/tsan/lit_tests/race_on_speculative_load.cc @@ -0,0 +1,24 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %t +// Regtest for https://code.google.com/p/thread-sanitizer/issues/detail?id=40 +// This is a correct program and tsan should not report a race. +#include +#include +int g; +__attribute__((noinline)) +int foo(int cond) { + if (cond) + return g; + return 0; +} +void *Thread1(void *p) { + long res = foo((long)p); + sleep(1); + return (void*) res; +} + +int main() { + pthread_t t; + pthread_create(&t, 0, Thread1, 0); + g = 1; + pthread_join(t, 0); +}