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

    <tr>
        <th>Summary</th>
        <td>
            Thread safety analysis - const ref to member not marked as a read
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          t-gehring
      </td>
    </tr>
</table>

<pre>
    When compiling with -Wthread-safety to enable the thread safety analysis from https://clang.llvm.org/docs/ThreadSafetyAnalysis.html and for convenience using the macros from the header file there:

```cpp
struct MyStruct {
    int x;
};

Mutex m;
MyStruct data;

// when not holding the lock, correct behaviour for mutable reference
{
    int & mutableRef = data.x; // fine, no write performed
}
{
    int & mutableRef = data.x; // "warning: writing variable 'data' requires holding mutex 'm' exclusively [-Wthread-safety-analysis]"
    mutableRef++; // due to this line performing a write
}
{
    int & mutableRef = data.x; // "warning: reading variable 'data' requires holding mutex 'm' [-Wthread-safety-analysis]"
    int copy = mutableRef; // due to this line performing a read
}
// when not holding the lock, incorrect behaviour for immutable reference
{
    int const & immutableRef = data.x; // no warning emitted
    int copy = immutableRef; // despite this line performing a read
}
```

I believe the last case should give a warning of "warning: reading variable 'data' requires holding mutex 'm' [-Wthread-safety-analysis]".


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VU2PmzAQ_TXmYiUiTgjJgcNuo0o97KW70p4NDOCuP6htks2_79iQj6ZbaXdVNSKAPTDz3vNjXJr6WDx3oGllVC-k0C09CN_R2bPvLPB65ngD_ki9oaB5KYH6LvxDjE4xrrk8OuFoY42infe9I8s7wr7iUUmu27mUezU3tsWJ2lQOL08xw2NMcDe9P--8kpitpo2xCEjvQQvQFdDBBWChsuKVNVOlMO4wC1jaiBGZhVA53ZH0dF6n41H1_TjjvB0qTx-Oj-MNye_HAMWf0J6-kuU0Q_Ld5T6eHwYPr1SdZ89Zau75zbOjAPQQ1NXG087I-kRDmuqFsC9I0lrA10vo-F6YwUbqavBRagsNMkIBTnBukBK2Pj37HRpKlruIYx4Y0Kl8IzSEStrQgxUeaA8WayioLxw_n50wduBWIy3UPRYIDPfcikiAsDwKw3Lk8nMQFtxZBhWlxJAKYXitJK7yHuSRkuz-xn6zk8VItsOSF5wXfITdh-MCrR4guNZ3aEz09Zl4qM1HLf69AgHzJxX4AOuArTL9MSK6kuC95EONW-7vMKvQb9tVqPcaFr9pN8p6fuevwgbDjsJSUML7k2H_EOA61bUE4Prg9w9ocOoV11_xNyQrBezHxic54q-4A-o6M8iatmjZYKcJqWn-oyHm1ziTuljW2-WWJ154CcXT2y16Nq0BrlQwiAJVYvsMK664fYGacjeJkwxWFr838xZ3hqGc41aBg9DTp8ust-YH-gKHwrkBQoPPssVqm3TFYrNdrKHaLqpNWa8Z8DVbbspVw1dlXq9XZSI5CuwKZIuUNBxoTBH8nu0SUbCUsXTF8sUmzVk-TwE5ZguesjUrOWRklYLiQp63mMQWEVI5tA6DUjjvLkHunGg1QCyH-fngO2MLP2uhs7gESSxeRPC_AMTYQQ4">