[llvm-bugs] [Bug 36162] New: Unlocking equivalent to scoped_lockable for Thread Safety Analysis

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 30 23:58:03 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36162

            Bug ID: 36162
           Summary: Unlocking equivalent to scoped_lockable for Thread
                    Safety Analysis
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: costan at gmail.com
                CC: llvm-bugs at lists.llvm.org

I'm trying to add thread safety annotations [1] to Chromium.

We have AutoLock type [2], which works like MutexLocker in the Clang
documentation [1], so it can be annotated with __attribute__((scoped_locker))
(SCOPED_CAPABILITY in the Clang documentation). Unfortunately, we also have an
AutoUnlock type [3] that's used to safely drop a lock while performing a block
of work.

Examples of usage:
https://cs.chromium.org/chromium/src/ipc/ipc_mojo_bootstrap.cc?q=AutoUnlock
https://cs.chromium.org/chromium/src/tools/gn/input_file_manager.cc?q=AutoUnlock

So, using thread safety annotations in Chromium is blocked on getting a
scoped_unlocker annotation that causes the type's constructor to remove the
lock from the set of held locks (used by the analyzer), and causes the type's
destructor to add the lock back to the set of held locks.

Shooting in the dark, I tried adding scoped_locker to AutoUnlock and annotating
the constructor with unlock_function and the destructor with
exclusive_lock_function, so this might be an alternative solution.

I will try to put together a patch for this, but I've never contributed to LLVM
before, and this isn't prioritized by my employer, so I'll probably be very
slow. Also, I won't be upset if someone else provides a patch before me.


[1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
[2] https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoLock
[3]
https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoUnlock

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180131/3658c092/attachment.html>


More information about the llvm-bugs mailing list