[compiler-rt] [TSan] Add interceptor for os_unfair_lock_lock_with_flags (PR #153815)

Dan Blackwell via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 19 04:05:31 PDT 2025


DanBlackwell wrote:

> > When does this test fail (even original version you modified)? Perhaps I'm missing something.
> > I think it should verify that the interceptor is actually active, i.e. create a race (e.g. print global_variable from _within_ Trace function), while omitting os_unfair_lock_lock calls, and check for the diagnostics appearing. Then test the same, enabling locks (so the interceptor can kick in and register synchronization) - and the diagnostics should be gone.
> 
> My understanding is that the new test case (extension of `compiler-rt/test/tsan/Darwin/os_unfair_lock.c`) would fail (because it would produce a false positive) without the new interceptor. @DanBlackwell, please sanity check that the test goes red if you remove the interceptor. I don't think we need to do any testing beyond that.

Here's the failure if I use the new test without the new interceptor:

```
command line:1:22: error: IMPLICIT-CHECK-NOT: excluded string found in input
-implicit-check-not='ThreadSanitizer'
                     ^
<stdin>:3:10: note: found here
WARNING: ThreadSanitizer: data race (pid=20905)
         ^~~~~~~~~~~~~~~

Input file: <stdin>
Check file: /Users/danblackwell/Development/OPEN-SOURCE-llvm/OPEN-SOURCE-source/compiler-rt/test/tsan/Darwin/os_unfair_lock.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
          1: global_variable = 2
          2: ==================
          3: WARNING: ThreadSanitizer: data race (pid=20905)
not:imp1              !~~~~~~~~~~~~~~                         error: no match expected
          4:  Write of size 8 at 0x000102178068 by thread T4:
          5:  #0 ThreadWithFlags os_unfair_lock.c:29 (os_unfair_lock.c.tmp:arm64+0x100000850)
          6:
          7:  Previous write of size 8 at 0x000102178068 by thread T3:
          8:  #0 ThreadWithFlags os_unfair_lock.c:29 (os_unfair_lock.c.tmp:arm64+0x100000850)
          .
          .
          .
>>>>>>

--

********************
********************
Failed Tests (1):
  ThreadSanitizer-arm64 :: Darwin/os_unfair_lock.c
```

I tend to write the test before I make the fix depending on how straightforward it is.

https://github.com/llvm/llvm-project/pull/153815


More information about the llvm-commits mailing list