<p dir="ltr">Yes, you're probably using clang as a host compiler, and it's too old. I've recently fixed a bug in clang led to broken debug info generation and caused similar test failures.</p>
<div class="gmail_quote">On Nov 26, 2012 5:35 AM, "David Blaikie" <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For what it's worth, running "ninja check-all" on my ubuntu machine is<br>
failing several of these tests. Do you know anything about this?<br>
<br>
Failing Tests (4):<br>
ThreadSanitizer :: race_on_mutex.c<br>
ThreadSanitizer :: simple_stack.c<br>
ThreadSanitizer :: simple_stack2.cc<br>
ThreadSanitizer :: write_in_reader_lock.cc<br>
<br>
<br>
for example:<br>
<br>
FAIL: ThreadSanitizer :: simple_stack.c (12713 of 12789)<br>
******************** TEST 'ThreadSanitizer :: simple_stack.c' FAILED<br>
********************<br>
Script:<br>
--<br>
/home/blaikie/local/Development/llvm/build/clang/x86-64/Debug/llvm/bin/clang<br>
-fsanitize=thread -fPIE -fno-builtin -g -Wall -pie -lpthread -ldl -O1<br>
/usr/local/google/home/blaikie/Development/llvm/src/projects/compiler-rt/lib/tsan/lit_tests/simple_stack.c<br>
-o /usr/local/google/home/blaikie/Development/llvm/build/clang/x86-64/Debug/llvm/projects/compiler-rt/lib/tsan/lit_tests/Output/simple_stack.c.tmp<br>
&& /usr/local/google/home/blaikie/Development/llvm/build/clang/x86-64/Debug/llvm/projects/compiler-rt/lib/tsan/lit_tests/Output/simple_stack.c.tmp<br>
2>&1 | FileCheck<br>
/usr/local/google/home/blaikie/Development/llvm/src/projects/compiler-rt/lib/tsan/lit_tests/simple_stack.c<br>
--<br>
Exit Code: 1<br>
Command Output (stderr):<br>
--<br>
/usr/local/google/home/blaikie/Development/llvm/src/projects/compiler-rt/lib/tsan/lit_tests/simple_stack.c:52:16:<br>
error: expected string not found in input<br>
// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:9{{(:3)?}} ({{.*}})<br>
^<br>
<stdin>:4:2: note: scanning from here<br>
#0 foo1 <null>:0 (simple_stack.c.tmp+0x000000005d7a)<br>
^<br>
--<br>
<br>
On Tue, Sep 18, 2012 at 12:23 AM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br>
> Author: samsonov<br>
> Date: Tue Sep 18 02:23:54 2012<br>
> New Revision: <a href="tel:164110" value="+49164110">164110</a><br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=164110&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=164110&view=rev</a><br>
> Log:<br>
> [TSan] port all output tests to lit and move them to lit_tests directory. This makes 'make check-tsan' command test both unit and output TSan tests. Old custom makefiles for running TSan tests are still functional as well.<br>
><br>
> Added:<br>
> compiler-rt/trunk/lib/tsan/lit_tests/free_race.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg<br>
> compiler-rt/trunk/lib/tsan/lit_tests/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a><br>
> compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh (with props)<br>
> compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c<br>
> compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc<br>
> compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc<br>
> Removed:<br>
> compiler-rt/trunk/lib/tsan/output_tests/<br>
> Modified:<br>
> compiler-rt/trunk/lib/tsan/Makefile.old<br>
> compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt<br>
><br>
> Modified: compiler-rt/trunk/lib/tsan/Makefile.old<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=164110&r1=164109&r2=164110&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=164110&r1=164109&r2=164110&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/Makefile.old (original)<br>
> +++ compiler-rt/trunk/lib/tsan/Makefile.old Tue Sep 18 02:23:54 2012<br>
> @@ -53,7 +53,7 @@<br>
><br>
> run: all<br>
> (ulimit -s 8192; ./tsan_test)<br>
> - ./output_tests/test_output.sh<br>
> + ./lit_tests/test_output.sh<br>
><br>
> presubmit:<br>
> # Debug build with clang.<br>
><br>
> Modified: compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt?rev=164110&r1=164109&r2=164110&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt?rev=164110&r1=164109&r2=164110&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt (original)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt Tue Sep 18 02:23:54 2012<br>
> @@ -1,10 +1,34 @@<br>
> configure_lit_site_cfg(<br>
> + ${CMAKE_CURRENT_SOURCE_DIR}/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a><br>
> + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg<br>
> + )<br>
> +<br>
> +configure_lit_site_cfg(<br>
> ${CMAKE_CURRENT_SOURCE_DIR}/Unit/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a><br>
> ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg<br>
> )<br>
><br>
> -# Run TSan unit tests.<br>
> -if(LLVM_INCLUDE_TESTS)<br>
> +if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}")<br>
> + # Run TSan output tests only if we're not cross-compiling,<br>
> + # and can be sure that clang would produce working binaries.<br>
> + set(TSAN_TEST_DEPS<br>
> + clang clang-headers FileCheck count not<br>
> + ${TSAN_RUNTIME_LIBRARIES}<br>
> + )<br>
> + set(TSAN_TEST_PARAMS<br>
> + tsan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg<br>
> + )<br>
> + if(LLVM_INCLUDE_TESTS)<br>
> + list(APPEND ASAN_TEST_DEPS TsanUnitTests)<br>
> + endif()<br>
> + add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"<br>
> + ${CMAKE_CURRENT_BINARY_DIR}<br>
> + PARAMS ${TSAN_TEST_PARAMS}<br>
> + DEPENDS ${TSAN_TEST_DEPS}<br>
> + )<br>
> + set_target_properties(check-tsan PROPERTIES FOLDER "TSan unittests")<br>
> +elseif(LLVM_INCLUDE_TESTS)<br>
> + # Otherwise run only TSan unit tests.<br>
> add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"<br>
> ${CMAKE_CURRENT_BINARY_DIR}/Unit<br>
> DEPENDS TsanUnitTests)<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/free_race.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/free_race.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/free_race.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,43 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include <stddef.h><br>
> +#include <unistd.h><br>
> +<br>
> +int *mem;<br>
> +pthread_mutex_t mtx;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + pthread_mutex_lock(&mtx);<br>
> + free(mem);<br>
> + pthread_mutex_unlock(&mtx);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(1000000);<br>
> + pthread_mutex_lock(&mtx);<br>
> + mem[0] = 42;<br>
> + pthread_mutex_unlock(&mtx);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + mem = (int*)malloc(100);<br>
> + pthread_mutex_init(&mtx, 0);<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread1, NULL);<br>
> + Thread2(0);<br>
> + pthread_join(t, NULL);<br>
> + pthread_mutex_destroy(&mtx);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: heap-use-after-free<br>
> +// CHECK: Write of size 4 at {{.*}} by main thread:<br>
> +// CHECK: #0 Thread2<br>
> +// CHECK: #1 main<br>
> +// CHECK: Previous write of size 8 at {{.*}} by thread 1:<br>
> +// CHECK: #0 free<br>
> +// CHECK: #1 Thread1<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/free_race2.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,26 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <stdlib.h><br>
> +<br>
> +void __attribute__((noinline)) foo(int *mem) {<br>
> + free(mem);<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) bar(int *mem) {<br>
> + mem[0] = 42;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + int *mem = (int*)malloc(100);<br>
> + foo(mem);<br>
> + bar(mem);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: heap-use-after-free<br>
> +// CHECK: Write of size 4 at {{.*}} by main thread:<br>
> +// CHECK: #0 bar<br>
> +// CHECK: #1 main<br>
> +// CHECK: Previous write of size 8 at {{.*}} by main thread:<br>
> +// CHECK: #0 free<br>
> +// CHECK: #1 foo<br>
> +// CHECK: #2 main<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/heap_race.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,20 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <stddef.h><br>
> +<br>
> +void *Thread(void *a) {<br>
> + ((int*)a)[0]++;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + int *p = new int(42);<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread, p);<br>
> + p[0]++;<br>
> + pthread_join(t, NULL);<br>
> + delete p;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/lit.cfg Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,86 @@<br>
> +# -*- Python -*-<br>
> +<br>
> +import os<br>
> +<br>
> +# Setup config name.<br>
> +<a href="http://config.name" target="_blank">config.name</a> = 'ThreadSanitizer'<br>
> +<br>
> +# Setup source root.<br>
> +config.test_source_root = os.path.dirname(__file__)<br>
> +<br>
> +def DisplayNoConfigMessage():<br>
> + lit.fatal("No site specific configuration available! " +<br>
> + "Try running your test from the build tree or running " +<br>
> + "make check-tsan")<br>
> +<br>
> +# Figure out LLVM source root.<br>
> +llvm_src_root = getattr(config, 'llvm_src_root', None)<br>
> +if llvm_src_root is None:<br>
> + # We probably haven't loaded the site-specific configuration: the user<br>
> + # is likely trying to run a test file directly, and the site configuration<br>
> + # wasn't created by the build system.<br>
> + tsan_site_cfg = lit.params.get('tsan_site_config', None)<br>
> + if (tsan_site_cfg) and (os.path.exists(tsan_site_cfg)):<br>
> + lit.load_config(config, tsan_site_cfg)<br>
> + raise SystemExit<br>
> +<br>
> + # Try to guess the location of site-specific configuration using llvm-config<br>
> + # util that can point where the build tree is.<br>
> + llvm_config = lit.util.which("llvm-config", config.environment["PATH"])<br>
> + if not llvm_config:<br>
> + DisplayNoConfigMessage()<br>
> +<br>
> + # Validate that llvm-config points to the same source tree.<br>
> + llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()<br>
> + tsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",<br>
> + "lib", "tsan", "lit_tests")<br>
> + if (os.path.realpath(tsan_test_src_root) !=<br>
> + os.path.realpath(config.test_source_root)):<br>
> + DisplayNoConfigMessage()<br>
> +<br>
> + # Find out the presumed location of generated site config.<br>
> + llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()<br>
> + tsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",<br>
> + "lib", "tsan", "lit_tests", "lit.site.cfg")<br>
> + if (not tsan_site_cfg) or (not os.path.exists(tsan_site_cfg)):<br>
> + DisplayNoConfigMessage()<br>
> +<br>
> + lit.load_config(config, tsan_site_cfg)<br>
> + raise SystemExit<br>
> +<br>
> +# Setup attributes common for all compiler-rt projects.<br>
> +compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",<br>
> + "lib", "lit.common.cfg")<br>
> +if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):<br>
> + lit.fatal("Can't find common compiler-rt lit config at: %r"<br>
> + % compiler_rt_lit_cfg)<br>
> +lit.load_config(config, compiler_rt_lit_cfg)<br>
> +<br>
> +# Setup environment variables for running ThreadSanitizer.<br>
> +config.environment['TSAN_OPTIONS'] = "atexit_sleep_ms=0"<br>
> +<br>
> +# Setup default compiler flags used with -faddress-sanitizer option.<br>
> +# FIXME: Review the set of required flags and check if it can be reduced.<br>
> +clang_tsan_cflags = ("-fthread-sanitizer "<br>
> + + "-fPIE "<br>
> + + "-fno-builtin "<br>
> + + "-g "<br>
> + + "-Wall "<br>
> + + "-pie "<br>
> + + "-lpthread "<br>
> + + "-ldl ")<br>
> +clang_tsan_cxxflags = "-ccc-clang-cxx -ccc-cxx " + clang_tsan_cflags<br>
> +config.substitutions.append( ("%clangxx_tsan ", (" " + config.clang + " " +<br>
> + clang_tsan_cxxflags + " ")) )<br>
> +config.substitutions.append( ("%clang_tsan ", (" " + config.clang + " " +<br>
> + clang_tsan_cflags + " ")) )<br>
> +<br>
> +# Define CHECK-%os to check for OS-dependent output.<br>
> +config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))<br>
> +<br>
> +# Default test suffixes.<br>
> +config.suffixes = ['.c', '.cc', '.cpp']<br>
> +<br>
> +# ThreadSanitizer tests are currently supported on Linux only.<br>
> +if config.host_os not in ['Linux']:<br>
> + config.unsupported = True<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/lit.site.cfg.in?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/lit.site.cfg.in?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a> (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/<a href="http://lit.site.cfg.in" target="_blank">lit.site.cfg.in</a> Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,19 @@<br>
> +## Autogenerated by LLVM/Clang configuration.<br>
> +# Do not edit!<br>
> +<br>
> +config.clang = "@LLVM_BINARY_DIR@/bin/clang"<br>
> +config.host_os = "@HOST_OS@"<br>
> +config.llvm_src_root = "@LLVM_SOURCE_DIR@"<br>
> +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"<br>
> +config.target_triple = "@TARGET_TRIPLE@"<br>
> +<br>
> +# LLVM tools dir can be passed in lit parameters, so try to<br>
> +# apply substitution.<br>
> +try:<br>
> + config.llvm_tools_dir = config.llvm_tools_dir % lit.params<br>
> +except KeyError,e:<br>
> + key, = e.args<br>
> + lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))<br>
> +<br>
> +# Let the main config do the real work.<br>
> +lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/memcpy_race.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,40 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stddef.h><br>
> +#include <stdio.h><br>
> +#include <string.h><br>
> +#include <unistd.h><br>
> +<br>
> +char *data = new char[10];<br>
> +char *data1 = new char[10];<br>
> +char *data2 = new char[10];<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + memcpy(data+5, data1, 1);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(500*1000);<br>
> + memcpy(data+3, data2, 4);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + fprintf(stderr, "addr=%p\n", &data[5]);<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK: Write of size 1 at [[ADDR]] by thread 2:<br>
> +// CHECK: #0 memcpy<br>
> +// CHECK: #1 Thread2<br>
> +// CHECK: Previous write of size 1 at [[ADDR]] by thread 1:<br>
> +// CHECK: #0 memcpy<br>
> +// CHECK: #1 Thread1<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,36 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stddef.h><br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +<br>
> +void *Thread1(void *x) {<br>
> + int *p = (int*)x;<br>
> + p[0] = 1;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(500*1000);<br>
> + char *p = (char*)x;<br>
> + p[2] = 1;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + int *data = new int(42);<br>
> + fprintf(stderr, "ptr1=%p\n", data);<br>
> + fprintf(stderr, "ptr2=%p\n", (char*)data + 2);<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, data);<br>
> + pthread_create(&t[1], NULL, Thread2, data);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + delete data;<br>
> +}<br>
> +<br>
> +// CHECK: ptr1=[[PTR1:0x[0-9,a-f]+]]<br>
> +// CHECK: ptr2=[[PTR2:0x[0-9,a-f]+]]<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK: Write of size 1 at [[PTR2]] by thread 2:<br>
> +// CHECK: Previous write of size 4 at [[PTR1]] by thread 1:<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/mop_with_offset2.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,36 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stddef.h><br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +<br>
> +void *Thread1(void *x) {<br>
> + usleep(500*1000);<br>
> + int *p = (int*)x;<br>
> + p[0] = 1;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + char *p = (char*)x;<br>
> + p[2] = 1;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + int *data = new int(42);<br>
> + fprintf(stderr, "ptr1=%p\n", data);<br>
> + fprintf(stderr, "ptr2=%p\n", (char*)data + 2);<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, data);<br>
> + pthread_create(&t[1], NULL, Thread2, data);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + delete data;<br>
> +}<br>
> +<br>
> +// CHECK: ptr1=[[PTR1:0x[0-9,a-f]+]]<br>
> +// CHECK: ptr2=[[PTR2:0x[0-9,a-f]+]]<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK: Write of size 4 at [[PTR1]] by thread 1:<br>
> +// CHECK: Previous write of size 1 at [[PTR2]] by thread 2:<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/mutex_destroy_locked.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,29 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <unistd.h><br>
> +<br>
> +void *Thread(void *p) {<br>
> + pthread_mutex_lock((pthread_mutex_t*)p);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_mutex_t m;<br>
> + pthread_mutex_init(&m, 0);<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread, &m);<br>
> + usleep(1000*1000);<br>
> + pthread_mutex_destroy(&m);<br>
> + pthread_join(t, 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex<br>
> +// CHECK: #0 pthread_mutex_destroy<br>
> +// CHECK: #1 main<br>
> +// CHECK: and:<br>
> +// CHECK: #0 pthread_mutex_lock<br>
> +// CHECK: #1 Thread<br>
> +// CHECK: Mutex {{.*}} created at:<br>
> +// CHECK: #0 pthread_mutex_init<br>
> +// CHECK: #1 main<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,31 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <stddef.h><br>
> +#include <unistd.h><br>
> +<br>
> +pthread_barrier_t B;<br>
> +int Global;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + pthread_barrier_init(&B, 0, 2);<br>
> + pthread_barrier_wait(&B);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(1000000);<br>
> + pthread_barrier_wait(&B);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread1, NULL);<br>
> + Thread2(0);<br>
> + pthread_join(t, NULL);<br>
> + pthread_barrier_destroy(&B);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_barrier2.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,31 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <stddef.h><br>
> +#include <unistd.h><br>
> +<br>
> +pthread_barrier_t B;<br>
> +int Global;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)<br>
> + pthread_barrier_destroy(&B);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)<br>
> + pthread_barrier_destroy(&B);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_barrier_init(&B, 0, 2);<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread1, NULL);<br>
> + Thread2(0);<br>
> + pthread_join(t, NULL);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_heap.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,47 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +<br>
> +void *Thread1(void *p) {<br>
> + *(int*)p = 42;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +void *Thread2(void *p) {<br>
> + *(int*)p = 44;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +void *alloc() {<br>
> + return malloc(99);<br>
> +}<br>
> +<br>
> +void *AllocThread(void* arg) {<br>
> + return alloc();<br>
> +}<br>
> +<br>
> +int main() {<br>
> + void *p = 0;<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, AllocThread, 0);<br>
> + pthread_join(t[0], &p);<br>
> + fprintf(stderr, "addr=%p\n", p);<br>
> + pthread_create(&t[0], 0, Thread1, (char*)p + 16);<br>
> + pthread_create(&t[1], 0, Thread2, (char*)p + 16);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// ...<br>
> +// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread 1:<br>
> +// CHCEKL #0 malloc<br>
> +// CHECK: #1 alloc<br>
> +// CHECK: #2 AllocThread<br>
> +// ...<br>
> +// CHECK: Thread 1 (finished) created at:<br>
> +// CHECK: #0 pthread_create<br>
> +// CHECK: #1 main<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/race_on_mutex.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,42 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <stddef.h><br>
> +#include <unistd.h><br>
> +<br>
> +pthread_mutex_t Mtx;<br>
> +int Global;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + pthread_mutex_init(&Mtx, 0);<br>
> + pthread_mutex_lock(&Mtx);<br>
> + Global = 42;<br>
> + pthread_mutex_unlock(&Mtx);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(1000000);<br>
> + pthread_mutex_lock(&Mtx);<br>
> + Global = 43;<br>
> + pthread_mutex_unlock(&Mtx);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + pthread_mutex_destroy(&Mtx);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK-NEXT: Read of size 1 at {{.*}} by thread 2:<br>
> +// CHECK-NEXT: #0 pthread_mutex_lock<br>
> +// CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:20{{(:3)?}} ({{.*}})<br>
> +// CHECK: Previous write of size 1 at {{.*}} by thread 1:<br>
> +// CHECK-NEXT: #0 pthread_mutex_init {{.*}} ({{.*}})<br>
> +// CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:11{{(:3)?}} ({{.*}})<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/race_with_finished_thread.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,43 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stddef.h><br>
> +#include <stdio.h><br>
> +#include <string.h><br>
> +#include <unistd.h><br>
> +<br>
> +// Ensure that we can restore a stack of a finished thread.<br>
> +<br>
> +int g_data;<br>
> +<br>
> +void __attribute__((noinline)) foobar(int *p) {<br>
> + *p = 42;<br>
> +}<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + foobar(&g_data);<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + usleep(1000*1000);<br>
> + g_data = 43;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK: Write of size 4 at {{.*}} by thread 2:<br>
> +// CHECK: Previous write of size 4 at {{.*}} by thread 1:<br>
> +// CHECK: #0 foobar<br>
> +// CHECK: #1 Thread1<br>
> +// CHECK: Thread 1 (finished) created at:<br>
> +// CHECK: #0 pthread_create<br>
> +// CHECK: #1 main<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/simple_race.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,26 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +<br>
> +int Global;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + Global = 42;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + Global = 43;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/simple_race.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,25 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +<br>
> +int Global;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + Global++;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + Global--;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/simple_stack.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,66 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +<br>
> +int Global;<br>
> +<br>
> +void __attribute__((noinline)) foo1() {<br>
> + Global = 42;<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) bar1() {<br>
> + volatile int tmp = 42; (void)tmp;<br>
> + foo1();<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) foo2() {<br>
> + volatile int v = Global; (void)v;<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) bar2() {<br>
> + volatile int tmp = 42; (void)tmp;<br>
> + foo2();<br>
> +}<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + usleep(1000000);<br>
> + bar1();<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + bar2();<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void StartThread(pthread_t *t, void *(*f)(void*)) {<br>
> + pthread_create(t, NULL, f, NULL);<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + StartThread(&t[0], Thread1);<br>
> + StartThread(&t[1], Thread2);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK-NEXT: Write of size 4 at {{.*}} by thread 1:<br>
> +// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:9{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack.c:14{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack.c:28{{(:3)?}} ({{.*}})<br>
> +// CHECK: Previous read of size 4 at {{.*}} by thread 2:<br>
> +// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:18{{(:26)?}} ({{.*}})<br>
> +// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:23{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:33{{(:3)?}} ({{.*}})<br>
> +// CHECK: Thread 1 (running) created at:<br>
> +// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})<br>
> +// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})<br>
> +// CHECK: Thread 2 ({{.*}}) created at:<br>
> +// CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})<br>
> +// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:38{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:44{{(:3)?}} ({{.*}})<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/simple_stack2.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,53 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +<br>
> +int Global;<br>
> +<br>
> +void __attribute__((noinline)) foo1() {<br>
> + Global = 42;<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) bar1() {<br>
> + volatile int tmp = 42;<br>
> + int tmp2 = tmp;<br>
> + (void)tmp2;<br>
> + foo1();<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) foo2() {<br>
> + volatile int tmp = Global;<br>
> + int tmp2 = tmp;<br>
> + (void)tmp2;<br>
> +}<br>
> +<br>
> +void __attribute__((noinline)) bar2() {<br>
> + volatile int tmp = 42;<br>
> + int tmp2 = tmp;<br>
> + (void)tmp2;<br>
> + foo2();<br>
> +}<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + usleep(1000000);<br>
> + bar1();<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread1, NULL);<br>
> + bar2();<br>
> + pthread_join(t, NULL);<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK-NEXT: Write of size 4 at {{.*}} by thread 1:<br>
> +// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:9{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:16{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}} ({{.*}})<br>
> +// CHECK: Previous read of size 4 at {{.*}} by main thread:<br>
> +// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:20{{(:28)?}} ({{.*}})<br>
> +// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:29{{(:3)?}} ({{.*}})<br>
> +// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:41{{(:3)?}} ({{.*}})<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,30 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <unistd.h><br>
> +<br>
> +int X = 0;<br>
> +<br>
> +void *Thread(void *p) {<br>
> + X = 42;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +void MySleep() {<br>
> + usleep(100*1000);<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread, 0);<br>
> + MySleep(); // Assume the thread has done the write.<br>
> + X = 43;<br>
> + pthread_join(t, 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// ...<br>
> +// CHECK: As if synchronized via sleep:<br>
> +// CHECK-NEXT: #0 usleep<br>
> +// CHECK-NEXT: #1 MySleep<br>
> +// CHECK-NEXT: #2 main<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/sleep_sync2.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,22 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <unistd.h><br>
> +<br>
> +int X = 0;<br>
> +<br>
> +void *Thread(void *p) {<br>
> + X = 42;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + usleep(100*1000);<br>
> + pthread_create(&t, 0, Thread, 0);<br>
> + X = 43;<br>
> + pthread_join(t, 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
> +// CHECK-NOT: As if synchronized via sleep<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/static_init1.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,27 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +<br>
> +struct P {<br>
> + int x;<br>
> + int y;<br>
> +};<br>
> +<br>
> +void *Thread(void *x) {<br>
> + static P p = {rand(), rand()};<br>
> + if (p.x > RAND_MAX || p.y > RAND_MAX)<br>
> + exit(1);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, Thread, 0);<br>
> + pthread_create(&t[1], 0, Thread, 0);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> + printf("PASS\n");<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/static_init2.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,33 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +<br>
> +struct Cache {<br>
> + int x;<br>
> + explicit Cache(int x)<br>
> + : x(x) {<br>
> + }<br>
> +};<br>
> +<br>
> +void foo(Cache *my) {<br>
> + static Cache *c = my ? my : new Cache(rand());<br>
> + if (c->x >= RAND_MAX)<br>
> + exit(1);<br>
> +}<br>
> +<br>
> +void *Thread(void *x) {<br>
> + foo(new Cache(rand()));<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, Thread, 0);<br>
> + pthread_create(&t[1], 0, Thread, 0);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> + printf("PASS\n");<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/static_init3.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,47 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include <sched.h><br>
> +<br>
> +struct Cache {<br>
> + int x;<br>
> +};<br>
> +<br>
> +Cache g_cache;<br>
> +<br>
> +Cache *CreateCache() {<br>
> + g_cache.x = rand();<br>
> + return &g_cache;<br>
> +}<br>
> +<br>
> +_Atomic(Cache*) queue;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + static Cache *c = CreateCache();<br>
> + __c11_atomic_store(&queue, c, 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + Cache *c = 0;<br>
> + for (;;) {<br>
> + c = __c11_atomic_load(&queue, 0);<br>
> + if (c)<br>
> + break;<br>
> + sched_yield();<br>
> + }<br>
> + if (c->x >= RAND_MAX)<br>
> + exit(1);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, Thread1, 0);<br>
> + pthread_create(&t[1], 0, Thread2, 0);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/static_init4.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,37 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include <sched.h><br>
> +<br>
> +struct Cache {<br>
> + int x;<br>
> + explicit Cache(int x)<br>
> + : x(x) {<br>
> + }<br>
> +};<br>
> +<br>
> +int g_other;<br>
> +<br>
> +Cache *CreateCache() {<br>
> + g_other = rand();<br>
> + return new Cache(rand());<br>
> +}<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + static Cache *c = CreateCache();<br>
> + if (c->x == g_other)<br>
> + exit(1);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, Thread1, 0);<br>
> + pthread_create(&t[1], 0, Thread1, 0);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> + printf("PASS\n");<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/static_init5.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,42 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include <sched.h><br>
> +<br>
> +struct Cache {<br>
> + int x;<br>
> + explicit Cache(int x)<br>
> + : x(x) {<br>
> + }<br>
> +};<br>
> +<br>
> +void *AsyncInit(void *p) {<br>
> + return new Cache((int)(long)p);<br>
> +}<br>
> +<br>
> +Cache *CreateCache() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, AsyncInit, (void*)rand());<br>
> + void *res;<br>
> + pthread_join(t, &res);<br>
> + return (Cache*)res;<br>
> +}<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + static Cache *c = CreateCache();<br>
> + if (c->x >= RAND_MAX)<br>
> + exit(1);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], 0, Thread1, 0);<br>
> + pthread_create(&t[1], 0, Thread1, 0);<br>
> + pthread_join(t[0], 0);<br>
> + pthread_join(t[1], 0);<br>
> + printf("PASS\n");<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_address.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,27 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +<br>
> +int X;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + X = 42;<br>
> + X = 66;<br>
> + X = 78;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + X = 11;<br>
> + X = 99;<br>
> + X = 73;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread1, 0);<br>
> + Thread2(0);<br>
> + pthread_join(t, 0);<br>
> +}<br>
> +<br>
> +// CHECK: ThreadSanitizer: reported 1 warnings<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/suppress_same_stacks.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,27 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +<br>
> +volatile int N; // Prevent loop unrolling.<br>
> +int **data;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + for (int i = 0; i < N; i++)<br>
> + data[i][0] = 42;<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + N = 4;<br>
> + data = new int*[N];<br>
> + for (int i = 0; i < N; i++)<br>
> + data[i] = new int;<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread1, 0);<br>
> + Thread1(0);<br>
> + pthread_join(t, 0);<br>
> + for (int i = 0; i < N; i++)<br>
> + delete data[i];<br>
> + delete[] data;<br>
> +}<br>
> +<br>
> +// CHECK: ThreadSanitizer: reported 1 warnings<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,49 @@<br>
> +#!/bin/bash<br>
> +<br>
> +ulimit -s 8192<br>
> +set -e # fail on any error<br>
> +<br>
> +ROOTDIR=$(dirname $0)/..<br>
> +<br>
> +# Assuming clang is in path.<br>
> +CC=clang<br>
> +CXX=clang++<br>
> +<br>
> +# TODO: add testing for all of -O0...-O3<br>
> +CFLAGS="-fthread-sanitizer -fPIE -O1 -g -fno-builtin -Wall"<br>
> +LDFLAGS="-pie -lpthread -ldl $ROOTDIR/rtl/libtsan.a"<br>
> +<br>
> +test_file() {<br>
> + SRC=$1<br>
> + COMPILER=$2<br>
> + echo ----- TESTING $(basename $1)<br>
> + OBJ=$SRC.o<br>
> + EXE=$SRC.exe<br>
> + $COMPILER $SRC $CFLAGS -c -o $OBJ<br>
> + $COMPILER $OBJ $LDFLAGS -o $EXE<br>
> + RES=$(TSAN_OPTIONS="atexit_sleep_ms=0" $EXE 2>&1 || true)<br>
> + if [ "$3" != "" ]; then<br>
> + printf "%s\n" "$RES"<br>
> + fi<br>
> + printf "%s\n" "$RES" | FileCheck $SRC<br>
> + if [ "$3" == "" ]; then<br>
> + rm -f $EXE $OBJ<br>
> + fi<br>
> +}<br>
> +<br>
> +if [ "$1" == "" ]; then<br>
> + for c in $ROOTDIR/lit_tests/*.{c,cc}; do<br>
> + if [[ $c == */failing_* ]]; then<br>
> + echo SKIPPING FAILING TEST $c<br>
> + continue<br>
> + fi<br>
> + COMPILER=$CXX<br>
> + case $c in<br>
> + *.c) COMPILER=$CC<br>
> + esac<br>
> + test_file $c $COMPILER<br>
> + done<br>
> + wait<br>
> +else<br>
> + test_file $ROOTDIR/lit_tests/$1 $CXX "DUMP"<br>
> +fi<br>
><br>
> Propchange: compiler-rt/trunk/lib/tsan/lit_tests/test_output.sh<br>
> ------------------------------------------------------------------------------<br>
> svn:executable = *<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_leak.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,17 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +<br>
> +void *Thread(void *x) {<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread, 0);<br>
> + pthread_join(t, 0);<br>
> + printf("PASS\n");<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: thread leak<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_leak2.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,17 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <stdio.h><br>
> +<br>
> +void *Thread(void *x) {<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread, 0);<br>
> + pthread_detach(t);<br>
> + printf("PASS\n");<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: thread leak<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/thread_leak3.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,14 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +<br>
> +void *Thread(void *x) {<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, 0, Thread, 0);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: thread leak<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/tiny_race.c Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,15 @@<br>
> +// RUN: %clang_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +int Global;<br>
> +void *Thread1(void *x) {<br>
> + Global = 42;<br>
> + return x;<br>
> +}<br>
> +int main() {<br>
> + pthread_t t;<br>
> + pthread_create(&t, NULL, Thread1, NULL);<br>
> + Global = 43;<br>
> + pthread_join(t, NULL);<br>
> + return Global;<br>
> +}<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/virtual_inheritance_compile_bug.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,15 @@<br>
> +// Regression test for <a href="http://code.google.com/p/thread-sanitizer/issues/detail?id=3" target="_blank">http://code.google.com/p/thread-sanitizer/issues/detail?id=3</a>.<br>
> +// The C++ variant is much more compact that the LLVM IR equivalent.<br>
> +<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <stdio.h><br>
> +struct AAA { virtual long aaa () { return 0; } }; // NOLINT<br>
> +struct BBB: virtual AAA { unsigned long bbb; }; // NOLINT<br>
> +struct CCC: virtual AAA { };<br>
> +struct DDD: CCC, BBB { DDD(); }; // NOLINT<br>
> +DDD::DDD() { }<br>
> +int main() {<br>
> + DDD d;<br>
> + printf("OK\n");<br>
> +}<br>
> +// CHECK: OK<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/vptr_benign_race.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,51 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <semaphore.h><br>
> +#include <stdio.h><br>
> +<br>
> +struct A {<br>
> + A() {<br>
> + sem_init(&sem_, 0, 0);<br>
> + }<br>
> + virtual void F() {<br>
> + }<br>
> + void Done() {<br>
> + sem_post(&sem_);<br>
> + }<br>
> + virtual ~A() {<br>
> + }<br>
> + sem_t sem_;<br>
> +};<br>
> +<br>
> +struct B : A {<br>
> + virtual void F() {<br>
> + }<br>
> + virtual ~B() {<br>
> + sem_wait(&sem_);<br>
> + sem_destroy(&sem_);<br>
> + }<br>
> +};<br>
> +<br>
> +static A *obj = new B;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + obj->F();<br>
> + obj->Done();<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + delete obj;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> + fprintf(stderr, "PASS\n");<br>
> +}<br>
> +// CHECK: PASS<br>
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race<br>
><br>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc?rev=164110&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc?rev=164110&view=auto</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc (added)<br>
> +++ compiler-rt/trunk/lib/tsan/lit_tests/vptr_harmful_race.cc Tue Sep 18 02:23:54 2012<br>
> @@ -0,0 +1,49 @@<br>
> +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s<br>
> +#include <pthread.h><br>
> +#include <semaphore.h><br>
> +#include <stdio.h><br>
> +<br>
> +struct A {<br>
> + A() {<br>
> + sem_init(&sem_, 0, 0);<br>
> + }<br>
> + virtual void F() {<br>
> + }<br>
> + void Done() {<br>
> + sem_post(&sem_);<br>
> + }<br>
> + virtual ~A() {<br>
> + sem_wait(&sem_);<br>
> + sem_destroy(&sem_);<br>
> + }<br>
> + sem_t sem_;<br>
> +};<br>
> +<br>
> +struct B : A {<br>
> + virtual void F() {<br>
> + }<br>
> + virtual ~B() { }<br>
> +};<br>
> +<br>
> +static A *obj = new B;<br>
> +<br>
> +void *Thread1(void *x) {<br>
> + obj->F();<br>
> + obj->Done();<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +void *Thread2(void *x) {<br>
> + delete obj;<br>
> + return NULL;<br>
> +}<br>
> +<br>
> +int main() {<br>
> + pthread_t t[2];<br>
> + pthread_create(&t[0], NULL, Thread1, NULL);<br>
> + pthread_create(&t[1], NULL, Thread2, NULL);<br>
> + pthread_join(t[0], NULL);<br>
> + pthread_join(t[1], NULL);<br>
> +}<br>
> +<br>
> +// CHECK: WARNING: ThreadSanitizer: data race<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>