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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy analzyer UndefinedBinaryOperatorResult false positive?
        </td>
    </tr>

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

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

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

<pre>
    While writing a small parsing library, i managed to find a code that is, as I believe, triggering a false positive with the static analyzer (sorry for the mess-code, had to change the variable naming):
```
int parse(void *p, void *out) {
  typedef struct __attribute__((__packed__)) {
    unsigned a : 1;
    unsigned b : 1;
    unsigned c : 1;
    unsigned d : 1;
    unsigned e : 1;
  } bits20_bits;
  typedef struct __attribute__((__packed__)) {
    unsigned bits0 : 12;
    unsigned bits12 : 4;
    unsigned bits16 : 4;
    unsigned bits20 : 5;
    unsigned bits25 : 3;
    unsigned bits28 : 4;
  } parse_t;
  parse_t *ptr = (parse_t *)p;
  const unsigned tmp_bits = ptr->bits20;
  const bits20_bits *bits = (bits20_bits *)&tmp_bits;
  if (!(bits->c != 0 || ptr->bits25 != 3 || bits->a != 1 ||
      (bits->b == 1 && bits->d == 0))) { 
    // ....
   return 0;
  }
  return -1;
}
 ```
When compiling with the static analyzer I get the following warning:
```
parser.c: error: The left operand of '!=' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult,-warnings-as-errors]
  if (!(bits->c != 0 || ptr->bits25 != 3 || bits->a != 1 ||
                ^
parser.c: note: The left operand of '!=' is a garbage value
```
Unless I'm missing something, I believe this is a false positive, as  obviously `c` has a value taken directly from the function parameter `p`, which the analyzer obviously has no idea if it is a garbage or not.
I use clang tidy with all checks other then `-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling` if that  matters.
clang-tidy version (from android-ndk 23b; happened also in 21d and 22b):
```
lang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 12.0.8git
  Optimized build.
  Default target: x86_64-apple-darwin21.4.0
  Host CPU: skylake
```

Hope this has enough information, will try to provide more if needed.
Also I hope this has not already fixed in a more-recent version, and if so I'm sorry for the inconvenience.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vl1vozgU_TXkxQIRE_LxkIe2maqVZjWj1XbnMTJggrfGRrZJJ_Pr99hAk7YzWWm12ogkmHt97tfxvRS6Om2_NUJy8mKEE-pAGLEtk5J0zFi_lqIwzJwiekcEaZliB14Rp0ktVAXlUlecuIY5IqzXYZY8koJLwY_cr50RhwM3A3LNpOWk0xamjjApXIO9nFjHnCgJwOXpBzckomurjTmRWpug0HJrY2_KQzYsOFA2TB14EB-ZEaxAEIq1sBTRTZTdROkuSm-iZTpeYSmUC5EBaH3UooKpm86DTgvdO2wn0ep22ECIO3W84jWcNH3pyH7PHIIqesf3e6Dg2u87Vj7zyq8373YT0isrDor7ZMErMo-ynwmLa8LymrC6JuQfhNFqRwrhLE33_u9C8p8F6nHTwTD9RbTQmNOgsriisfwnDTqYya9o5EEju6Kx_mDF5yiwZO8uno5PAmUcSJrtPFEvniIj3YV-qZV1Z1uu7ULGw0YAxFH2aYjhw56L-njc110w904U6rCcoC-ARE1CzebjHm8NNMIaOMja6g7XGzfySZpN0mkfmyTzUXLOJCEX-J7Du1GPLnG9IlSTJB2IM3KHnIEieo-LJPi8PjTc9UaR9G1lpttRGp_JfRa-O_XfGq6Q2rYT0jeiX_adR3LgLkhqLaV-CcrMKN9TftFQQvlNUnoKcWO08Td_AEHy2hHdccPQJ7WvxmrIIm7QK9ENDswU6KboXrLHOc1vS4mOFk_eoN8ZnjwpHEkB_twKhTb8xQM6bX7ntpfoVHfx6J-NmY2DAzbKd_87C86fKP_0MTNKO_4vE_PTrD8piYlAHrGlJa2wYVJZ3XLXhP5_dx5CKCdAA-7b8TNOK6KLo9C9lSfPmhJfDBivPZTFsWdwpxKGlw4qtdH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