<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56815>56815</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] Thread Safety Analysis disables analysis within annotated methods
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            enhancement,
            clang:diagnostics
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ilovepi
      </td>
    </tr>
</table>

<pre>
    Safety annotations like `ACQUIRE` and `RELEASE` on methods disable analysis within the function body, which can be problematic if an unrelated lock in involved.

This is a problem we ran into on Fuchsia, where we make heavy use of Thread Safety Annotations. The underlying bug in our codebase was hard to diagnose for a variety of reasons, but because we use these annotations our engineers only verified the correctness/presence of the annotations instead of investigating the locking logic immediately.

In our case, we had a mutex implementation that needed to obtain a spinlock to interact with the scheduler. Both the mutex and spinlocks were correctly annotated using  `ACQUIRE` and `RELEASE` capabilities. However, our mutex also needed to interact with an external lock (i.e, one for the scheduler that was not `this` or a member variable). Unfortunately, the current annotations do not provide a way to communicate this to the analysis. So, if analysis is disabled in the method body completely, then bugs using the external lock are not discovered.

I've included a more complete example on godbolt https://godbolt.org/z/fen64fv5e

The upstream bug can be found here https://fxbug.dev/105399

Is it possible to support this type of analysis? Perhaps by extending the annotations? or is this a more fundamental limitation? 



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyFVcGSmzgQ_Rp8US2FwXjsgw9OZqZ2qvawm0k-QKDGaCMkShL2eL9-XwsmYyeHVGEQUvO6-3W_duPU9fAqO4pXIa11UUbtbBBGfyeRbYvj53--vXx5wgrHine-PP31dHxNO86KgWLvVBBKB9kYgpE016CDuOjYaytiT6KbbMuoooGzrPwsLr1ue9FK7JAYvcOHA_y2QncAEJP1ZGQkJYxrvwugaHt25kwqz4rHrDjO96893OCS7xDiQsJLto6OY3ue2j5oOXskT3w-SOTV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