<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Unlocking equivalent to scoped_lockable for Thread Safety Analysis"
   href="https://bugs.llvm.org/show_bug.cgi?id=36162">36162</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unlocking equivalent to scoped_lockable for Thread Safety Analysis
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>costan@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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:
<a href="https://cs.chromium.org/chromium/src/ipc/ipc_mojo_bootstrap.cc?q=AutoUnlock">https://cs.chromium.org/chromium/src/ipc/ipc_mojo_bootstrap.cc?q=AutoUnlock</a>
<a href="https://cs.chromium.org/chromium/src/tools/gn/input_file_manager.cc?q=AutoUnlock">https://cs.chromium.org/chromium/src/tools/gn/input_file_manager.cc?q=AutoUnlock</a>

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] <a href="https://clang.llvm.org/docs/ThreadSafetyAnalysis.html">https://clang.llvm.org/docs/ThreadSafetyAnalysis.html</a>
[2] <a href="https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoLock">https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoLock</a>
[3]
<a href="https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoUnlock">https://cs.chromium.org/chromium/src/base/synchronization/lock.h?q=AutoUnlock</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>