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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect thread safety analysis warning on accessing union member.
        </td>
    </tr>

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

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

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

<pre>
    See [godbolt](https://godbolt.org/z/bc81b64ej)

```
#define LOCKABLE __attribute__((lockable))
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__((exclusive_lock_function(__VA_ARGS__)))
#define UNLOCK_FUNCTION(...) __attribute__((unlock_function(__VA_ARGS__)))
#define GUARDED_BY(x) __attribute__((guarded_by(x)))

class LOCKABLE Mutex {
 public:
  void Lock() EXCLUSIVE_LOCK_FUNCTION();
  void Unlock() UNLOCK_FUNCTION();
};

class Test {
  Mutex mu;

  union {
    int a GUARDED_BY(mu);
    int b GUARDED_BY(mu);
  } ;
 void test1() {  
    mu.Lock();
    a = 0;   // unexpected warning: writing variable 'a' requires holding mutex 'mu' exclusively
 mu.Unlock();
  }
};
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE1v2zgQ_TWjy6CCREqRfNDBjuMi2GwKNHWxexIoamyzocgsP9J4f_1Cthrb3WywKGDQGvDNezOP5Ajv1dYQNVAuoFwmIoaddc3OPpIySWf7ffNAhFAutrbvrA5QLoHVuxCePPA5sBWw1bSVWrcFtvob2KqTdd5dFfQN2AyyJWTzab3Kpt8xZLynjTKEd5-uf5sv7m6wbUUITnUxUNsCq4HV2spH0WkauV7pXjNv_ri-Wz_cfr1pR452tb6__nL76R5YnaYpsNlbjPQidfTqmdqRu91EI4OyBljdtl_n7fzzx4cROntbcX3__5Wi-RWFj-v55-XNsl38Cax--Q_qbRSup77t9hPoguuwSi28P3n7ewz0glAtjrv4FDut5HiMxxifrerxzsrHg8LsHW9HIb64yFsfWp0y_-3ReQZUy9P3WaVfyIez-qaCh_gTGDEaZc05ElGZgOLSuSFelnkEde-DoFriKTx0FsiHfGoMqgXiiXCI6cmvCymBwJeYAV8g4vGdYDT08kQyUI_fhTPKbIHP8btTQZktPgunxnuOwCoBrEJHf0XlyOPO6n5EDMcDZNVYdIWv11jvJ90hpufHcNnWG97_eI5J3_B-xmcioSavspLnWcGLZNfIbpbziuWd4EXF6qxiucyLjK54zUsuukQ1LGNFludlNmMZL9Iqq2mz6ZnMN6XsqYQio0EonWr9PIwjIlHeR2qqOud5okVH2h-mD2NSi4MjvRJbY31Q0gNj41hyzZj9oYtbD0WmlQ_-xBdU0NTcGmmdIxkw7ByJHr3YUNijMELvvfI_HEdrUEhJ3o_B8SINNHTk0iQ63fw02lTYxS6VdgC2GhWnvw9Pzn4jGYCtDu14YKtDR_8EAAD__5AFi_Y">