summaryrefslogtreecommitdiff
path: root/test/tsan/Darwin
AgeCommit message (Collapse)Author
2017-09-22Deflake the "xpc-race.mm" test.Kuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@314014 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-10Fix-up for r307537: We need to #include stdint.h to get int32_t.Kuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307557 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-10[tsan] Add support for running TSan tests on iOS simulator and devicesKuba Mracek
Differential Revision: https://reviews.llvm.org/D35157 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307537 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-05[tsan] Use pthread_sigmask instead of sigprocmask to block signals in a ↵Kuba Mracek
thread on Darwin On Darwin, sigprocmask changes the signal mask for the entire process. This has some unwanted consequences, because e.g. internal_start_thread wants to disable signals only in the current thread (to make the new thread inherit the signal mask), which is currently broken on Darwin. This patch switches to pthread_sigmask. Differential Revision: https://reviews.llvm.org/D35016 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307212 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-03fix trivial typos in comments; NFCHiroshi Inoue
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307005 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-03[tsan] Detect races on modifying accesses in Swift codeKuba Mracek
This patch allows the Swift compiler to emit calls to `__tsan_external_write` before starting any modifying access, which will cause TSan to detect races on arrays, dictionaries and other classes defined in non-instrumented modules. Races on collections from the Swift standard library and user-defined structs and a frequent cause of subtle bugs and it's important that TSan detects those on top of existing LLVM IR instrumentation, which already detects races in direct memory accesses. Differential Revision: https://reviews.llvm.org/D31630 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302050 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-27TSan: update line number after XFAIL on iOS.Tim Northover
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301560 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-26XFAIL the TSan XPC tests on iOS. XPC isn't available on iOS.Kuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301459 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-24[tsan] Include __tsan_external_* API from a header file instead of declaring ↵Kuba Mracek
them manually. NFC. Differential Revision: https://reviews.llvm.org/D32384 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301190 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-24[tsan] Remove the extra word "object" from description of external racesKuba Mracek
Differential Revision: https://reviews.llvm.org/D32383 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301189 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21[tsan] Add a test for "external" API that checks the dup suppression is ↵Kuba Mracek
based on the caller PC We need to make sure that the "external" API isn't dup'ing all data races into a single one (because the stack might look the same) and suppressing all external races. This works now, so just adding a test for that. Differential Revision: https://reviews.llvm.org/D31734 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301011 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21[tsan] Ignore memory accesses for libignored modules for "external" racesKuba Mracek
On Darwin, the setting ignore_noninstrumented_modules is used to suppress false positives in code that users don't have control of. The recently added "external" API (which can be used to detect races on objects provided by system libraries, but the race is actually user's fault) ignores this flag and it can report issues in non-instrumented modules. This patch fixes that. Differential Revision: https://reviews.llvm.org/D31553 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301000 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21[tsan] Don't report bugs from interceptors called from libignored modulesKuba Mracek
This patch make sure we don't report deadlocks and other bug types when we're inside an interceptor that was called from a noninstrumented module (when ignore_noninstrumented_modules=1 is set). Adding a testcase that shows that deadlock detection still works on Darwin (to make sure we're not silencing too many reports). Differential Revision: https://reviews.llvm.org/D31449 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300998 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDsKuba Mracek
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD). Differential Revision: https://reviews.llvm.org/D31774 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300473 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-30[tsan] Add interceptor for xpc_connection_cancel to avoid false positivesKuba Mracek
TSan reports a false positive when using xpc_connection_cancel. We're missing a happens-before edge from xpc_connection_cancel to the event handler on the same connection. Differential Revision: https://reviews.llvm.org/D31475 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299086 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-26[tsan] Only Acquire/Release GCD queues if they're not NULLKuba Mracek
While it's usually a bug to call GCD APIs, such as dispatch_after, with NULL as a queue, this often "somehow" works and TSan should maintain binary compatibility with existing code. This patch makes sure we don't try to call Acquire and Release on NULL queues, and add one such testcase for dispatch_after. Differential Revision: https://reviews.llvm.org/D31355 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298820 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-24Update debug_external.cc testcase to use TSan-invisible barriers to reduce ↵Kuba Mracek
flakiness. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298707 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-24Update the Darwin/external.cc testcase to use rpath. This means we can move ↵Kuba Mracek
the test output executables and still be able to run them. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298682 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-22Re-commit of r295318, which was reverted due to AArch64 flakiness. Moving ↵Kuba Mracek
the test to Darwin only. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295801 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-13Fixup for r293885: Update external.cc testcase to include the forgotten ↵Kuba Mracek
stdlib.h. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295002 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[tsan] Provide API for libraries for race detection on custom objectsKuba Mracek
This patch allows a non-instrumented library to call into TSan runtime, and tell us about "readonly" and "modifying" accesses to an arbitrary "object" and provide the caller and tag (type of object). This allows TSan to detect violations of API threading contracts where "read-only" methods can be called simulatenously from multiple threads, while modifying methods must be exclusive. Differential Revision: https://reviews.llvm.org/D28836 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293885 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-02[tsan] Properly describe GCD worker threads in reportsKuba Mracek
When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports. This patch avoids that and instead prints "Thread T3 (...) is a GCD worker thread". Differential Revision: https://reviews.llvm.org/D29103 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293882 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-26[tsan] Fix os_id of main threadKuba Mracek
Currently, os_id of the main thread contains the PID instead of a thread ID. Let's fix this. Differential Revision: https://reviews.llvm.org/D29106 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293201 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24[tsan] Enable ignore_noninstrumented_modules=1 on Darwin by defaultKuba Mracek
TSan recently got the "ignore_noninstrumented_modules" flag, which disables tracking of read and writes that come from noninstrumented modules (via interceptors). This is a way of suppressing false positives coming from system libraries and other noninstrumented code. This patch turns this on by default on Darwin, where it's supposed to replace the previous solution, "ignore_interceptors_accesses", which disables tracking in *all* interceptors. The new approach should re-enable TSan's ability to find races via interceptors on Darwin. Differential Revision: https://reviews.llvm.org/D29041 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@292981 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11[tsan] Implement a 'ignore_noninstrumented_modules' flag to better suppress ↵Kuba Mracek
false positive races On Darwin, we currently use 'ignore_interceptors_accesses', which is a heavy-weight solution that simply turns of race detection in all interceptors. This was done to suppress false positives coming from system libraries (non-instrumented code), but it also silences a lot of real races. This patch implements an alternative approach that should allow us to enable interceptors and report races coming from them, but only if they are called directly from instrumented code. The patch matches the caller PC in each interceptors. For non-instrumented code, we call ThreadIgnoreBegin. The assumption here is that the number of instrumented modules is low. Most likely there's only one (the instrumented main executable) and all the other modules are system libraries (non-instrumented). Differential Revision: https://reviews.llvm.org/D28264 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291631 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16Follow-up for r289831: Lower the unjoined thread count to 100 in the ↵Kuba Mracek
libcxx-future.mm testcase. Turns out 1000 unjoined threads are a bit too rough in certain environments. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289971 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15[tsan] Add interceptor for libcxx __shared_count::__release_shared()Kuba Mracek
We already have an interceptor for __shared_weak_count::__release_shared, this patch handles __shared_count::__release_shared in the same way. This should get rid of TSan false positives when using std::future. Differential Revision: https://reviews.llvm.org/D27797 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289831 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-24[tsan] Add support for GCD dispatch_suspend and dispatch_resumeKuba Mracek
GCD queues can be suspended and resumed with dispatch_suspend and dispatch_resume. We need to add synchronization between the call to dispatch_resume and any subsequent executions of blocks in the queue that was resumed. We already have an Acquire(q) before the block executes, so this patch just adds the Release(q) in an interceptor of dispatch_resume. Differential Revision: https://reviews.llvm.org/D27112 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287902 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-12[tsan] Test that false races from ObjC's dealloc, .cxx_destruct, and ↵Anna Zaks
initialize are ignored Differential Revision: https://reviews.llvm.org/D26228 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286693 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07[tsan] Change nullptr to NULL in realloc-zero.cc test. Some environments ↵Kuba Brecka
don't have nullptr. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286166 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-07[tsan] Cast floating-point types correctly when instrumenting atomic ↵Kuba Brecka
accesses, compiler-rt part Although rare, atomic accesses to floating-point types seem to be valid, i.e. `%a = load atomic float ...`. The TSan instrumentation pass however tries to emit inttoptr, which is incorrect, we should use a bitcast here. Anyway, IRBuilder already has a convenient helper function for this. Differential Revision: https://reviews.llvm.org/D26266 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286136 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-31[tsan] Add support for GCD target queuesKuba Brecka
GCD (libdispatch) has a concept of “target queues”: Each queue has either an implicit or explicit target queue, where the task is handed over to when it’s time to execute it. For example, a concurrent queue can have a serial target queue (effectively making the first queue serial), or multiple queues can have the same serial target queue (which means tasks in all the queues are mutually excluded). Thus we need to acquire-release semantics on the full “chain” of target queues. This patch changes the way we Acquire() and Release() when executing tasks in queues. Now we’ll walk the chain of target queues and synchronize on each queue that is serial (or when dealing with a barrier block). This should avoid false positives when using dispatch_set_target_queue(). Differential Revision: https://reviews.llvm.org/D25835 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@285613 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-14[tsan] Fix hanging gcd-apply and gcd-apply-race tests on macOS SierraKuba Brecka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281462 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-08[tsan] Support C++11 call_once in TSan on DarwinKuba Brecka
This patch adds a wrapper for call_once, which uses an already-compiled helper __call_once with an atomic release which is invisible to TSan. To avoid false positives, the interceptor performs an explicit atomic release in the callback wrapper. Differential Revision: https://reviews.llvm.org/D24188 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280920 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02[tsan] Fix the behavior of OSAtomicTestAndClearKuba Brecka
The system implementation of OSAtomicTestAndClear returns the original bit, but the TSan interceptor has a bug which always returns zero from the function. This patch fixes this and adds a test. Differential Revision: https://reviews.llvm.org/D23061 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277461 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02[tsan] Fix behavior of realloc(nullptr, 0) on DarwinKuba Brecka
On Darwin, there are some apps that rely on realloc(nullptr, 0) returning a valid pointer. TSan currently returns nullptr in this case, let's fix it to avoid breaking binary compatibility. Differential Revision: https://reviews.llvm.org/D22800 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277458 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-12Disable the "gcd-io-race.mm" test to investigate bot hangs due to the test ↵Kuba Brecka
being deadlocked. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275182 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11[tsan] Add support for GCD IO channels on DarwinKuba Brecka
This patch adds interceptors for dispatch_io_*, dispatch_read and dispatch_write functions. This avoids false positives when using GCD IO. Adding several test cases. Differential Revision: http://reviews.llvm.org/D21889 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275071 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-09test: Use %clangxx in objc++ test filesSaleem Abdulrasool
These test in this change are objc++, but are built using %clang, not %clangxx. The reason this works is the driver has been adding -lc++ for sanitizer enabled builds. By making these tests use %clangxx, they no longer depend on the driver linking to c++. Doing so will allow us to prevent overlinking of libc++ for applications. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274989 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07[tsan] Avoid false positives with GCD data callbacksKuba Brecka
This patch adds synchronization between the creation of the GCD data object and destructor’s execution. It’s far from perfect, because ideally we’d want to synchronize the destruction of the last reference (via dispatch_release) and the destructor’s execution, but intercepting objc_release is problematic. Differential Revision: http://reviews.llvm.org/D21990 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274749 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-06[tsan] Fix false positives with GCD dispatch_source_*Kuba Brecka
We already have interceptors for dispatch_source API (e.g. dispatch_source_set_event_handler), but they currently only handle submission synchronization. We also need to synchronize based on the target queue (serial, concurrent), in other words, we need to use dispatch_callback_wrap. This patch implements that. Differential Revision: http://reviews.llvm.org/D21999 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274619 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-05[tsan] Synchronize leaving a GCD group with notificationsKuba Brecka
In the patch that introduced support for GCD barrier blocks, I removed releasing a group when leaving it (in dispatch_group_leave). However, this is necessary to synchronize leaving a group and a notification callback (dispatch_group_notify). Adding this back, simplifying dispatch_group_notify_f and adding a test case. Differential Revision: http://reviews.llvm.org/D21927 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274549 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-05[tsan] dispatch_once interceptor will cause a crash/deadlock when the ↵Kuba Brecka
original dispatch_once is used Because we use SCOPED_TSAN_INTERCEPTOR in the dispatch_once interceptor, the original dispatch_once can also be sometimes called (when ignores are enabled or when thr->is_inited is false). However the original dispatch_once function doesn’t expect to find “2” in the storage and it will spin forever (but we use “2” to indicate that the initialization is already done, so no waiting is necessary). This patch makes sure we never call the original dispatch_once. Differential Revision: http://reviews.llvm.org/D21976 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274548 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-01[tsan] Relax the "ignored-interceptors.mm" testcase. The test has been ↵Kuba Brecka
flaky because it's detecting a false positive race (coming from a system library) and sometimes that race is detected after we're printing "Done". git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274346 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-29[tsan] Stop extending the block’s lifetime in dispatch_group_asyncKuba Brecka
The dispatch_group_async interceptor actually extends the lifetime of the executed block. This means the destructor of the block (and captured variables) is called *after* dispatch_group_leave, which changes the semantics of dispatch_group_async. This patch fixes that. Differential Revision: http://reviews.llvm.org/D21816 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274117 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-28Adapt the "objc-race.mm" test to use ignore_interceptors_accesses=1. All ↵Kuba Brecka
Obj-C/Darwin tests currently need this to avoid false positives. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@274014 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-27[tsan] Add HB edges for GCD barrier blocksKuba Brecka
Adding support for GCD barrier blocks in concurrent queues. This uses two sync object in the same way as read-write locks do. This also simplifies the use of dispatch groups (the notifications act as barrier blocks). Differential Revision: http://reviews.llvm.org/D21604 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@273893 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-26[tsan] Intercept libcxx __release_shared to avoid false positive with ↵Kuba Brecka
weak_ptrs and destructors in C++ There is a "well-known" TSan false positive when using C++ weak_ptr/shared_ptr and code in destructors, e.g. described at <https://llvm.org/bugs/show_bug.cgi?id=22324>. The "standard" solution is to build and use a TSan-instrumented version of libcxx, which is not trivial for end-users. This patch tries a different approach (on OS X): It adds an interceptor for the specific function in libc++.dylib, which implements the atomic operation that needs to be visible to TSan. Differential Revision: http://reviews.llvm.org/D21609 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@273806 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-25[tsan] Change some OS X tests to include system headers (xpc.h, mman.h) more ↵Kuba Brecka
explicitly. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270713 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19[tsan] Add support for GCD's dispatch_after and dispatch_after_fKuba Brecka
We're missing interceptors for dispatch_after and dispatch_after_f. Let's add them to avoid false positives. Added a test case. Differential Revision: http://reviews.llvm.org/D20426 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270071 91177308-0d34-0410-b5e6-96231b3b80d8