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

    <tr>
        <th>Summary</th>
        <td>
            Clang Static Analyzer should issue a warning on mutual assignment
        </td>
    </tr>

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

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

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

<pre>
    Here is a minimal test case showing mutual assignment where we do `b = a;` followed by `a = b;`:

```
int main(void) {
        int a = 0;
        int b = a;
        int c = 1;
        a = b;
        return a*b*c;
}
```

I tested this with `clang --analyze -Wall -Werror /tmp/ab.c` and `clang-tidy /tmp/ab.c --`, but saw no warnings.

The second statement `a = b;` is redundant. We just found an instance of this in OpenZFS:

https://github.com/openzfs/zfs/pull/14565/files#r1124115812

A quick search revealed that PVS Studio has a check for this:

https://pvs-studio.com/en/docs/warnings/v587/
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8U02PpDYQ_TXmUqJlCuiPA4eeHaHklEgTZaTcCrtovGvsjm0a9f76CJjZzG6vFiEj_FzPr15VUYzm4pgbUT-J-jmjKQ0-NOFOPuu8vje_cWAwEQhG48xIFhLHBIoiQxz8bNwFxilNZGHjGtklmIclbGbQHsRediDKZyBRPom9hN5b62fW0N0XkFaw20BRnoV8FvJ93cu3d_01LsFIxgk83rzRAk8gDk8bBm_PcmajlAvlA_ZBywOmVqx4wD5I_G4_cJqCAxJ47gSe1bcD4vD80wS29ffVQ9aQBhNhNmlYfFCW3AXynBzZ-1eG_JWshfyVQ_ABBLZpvApsqdupxUVy-ltUnoy-f38E8ny5FT9BNyWINIPzMFNwxl3i7qOavwaGyMo7DTFR4rWAP9ZlaYHAenKaXNrBK8PnKSbo_eQ0kAPjYiKnGHy_ZWUc_HFl90_78kNJh5SucdnDVmB7MWmYup3yo8DWX9l97aPAdluvk7UC26Kq97XAtjeWo8AyFAVWRVEfC_xIfIZ_J6O-QGQKaoDANya7mkwJ_vz7BV7SpI2HgZZuVgOrL9D7sMr9pcbrLeZxjX3TyU5gq71aNL5bKrC91ceDwDbTTalP5Ykybor94VhUh0qW2dD0dbXv98jVqar6CntdUH3sj11ZVHSsVZ2ZBiWWspQHKWWJuCtRImlZ9RpVKVGLSvJIxu6svY07Hy6ZiXHiZl8gnjJLHdu4TjKi4xlWUCAugx2aJSbvpksUlbQmpvg_SzLJcvNpbcCXRMkoOG9dGJYhn6zeuIDeWwi8exz7bAq2-UV9l_vePvk1-M-sksB2ZV78W7P4LwAA___z2F1t">