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

    <tr>
        <th>Summary</th>
        <td>
            Clang thread-safety analysis not producing warnings for multiple objects of the same type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Given the following code (full code in godbolt link below) Clang doesn't report any warnings for accessing b.some_field even though b.lock is not locked at any point (removing a.lock.acquire() + a.lock.release() calls makes the warning appear but that's obviously not something that you should have to do as they are two distinct objects):
```cpp
struct CAPABILITY("spinlock") Spinlock {
    void acquire() ACQUIRE();
    void release() RELEASE();
};

struct Foo {
    Spinlock lock;
    bool some_field GUARDED_BY(lock);
};

void foobar() {
    Foo a {};
    Foo b {};
    a.lock.acquire();
 b.some_field = true;
 a.lock.release();
}
```
[godbolt](https://godbolt.org/z/dPqb6aqrx)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsU8Fu4zgM_Rr5QjRw6ThODj44TTMoMIeZzs5hTwNJpmNtFdOV5GS9X7-Q42Sa3QIBIprU43sin_TeHDqiUuRbke8SOYSWXfn9bDptEsX1WH4xJ-ogtAQNW8tn0x1Ac00gcN0M1l4C08GBa8U2gDXdGyiyfBa4gScruwPUTL4TWARw1LMLILsRztJ1pjt4aNiB1Jq8j-Bq4flIvxpDtga6NOfh0IJaWNZvYDx0HCCeqQZ5werZdCFScnTkU4SRU_VC6vfBOBK4jmwEbq8JR5akvya0tNbDUb6Rn7TO3ED2PUkHaggQWhkEFh5YnQwP3o4Tj0g2tLE2FsDIA_iWB1tDK08EgaFmkBPqCNIRhDNDbXwwnQ7A6i_SwQvciKwSaSVW6eWn-16klQ9u0AGeqm_V9uXryx9_TnTR96aLIgRiJP9jDkEUW5FWAAAnNjXca6-evv98eX2-RCK7q7x_jNfnr8_Vj7tKUezmw43UnvlDwxuHidcNXTFb-DDPLz-r193z7tc2KrlI-KTDxKlhVtJdB3drFNvKKb5euH5V__v62Q7M2bstE9kOghtozn22Ib9JfhhSPOfbefFFvhO4bkPofZwl7gXu59SC3UHg_h-B-_rbu1rJd_e3wE1Sl1m9yTYyofKxyDarPENMk7bUtUpVvkxVulyvVF5gsVYrpfO8yPWmwTwxJaaYp_iY42OaYrrI11lBqWz0UiGS0mKZ0lEau7D2dIztE-P9QOUjFtlyk1ipyPrJ9Yg6WjSuUr5LXBkvPKjh4MUytcYH_xsimGCpvDg6tI5k_eBlQ2EE2Uk7-tmZveN60NERdw4_DjaY3tJ154GbyWpeHgnC2FMyOFv-5_1MaAe10HwUuI885r-H3nEEEbifdHmB-1naqcR_AwAA__9MYoUP">