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

    <tr>
        <th>Summary</th>
        <td>
            False positives when using misc-redundant-expression clang-tidy checker.
        </td>
    </tr>

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

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

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

<pre>
    The misc-redundant-expression produces a warning with latest trunk build where it should not.
In the example below two different defines are being compared. Those defines different, yet happens to have the same value due to compile defines configuration. 
The warning generated is:
`
<source>:13:20: warning: both sides of operator are equivalent [misc-redundant-expression]
 13 |   if (ci && (VAL_1 != VAL_2))
`
where operator != is highlighted.
I believe the programmer intention is very clear here as programmer wants to have function foo return 0 or 1 depending on the define passed into the compilation line, so the condition is not redundant.

I have created a minimal reproducer for the issue:
`
//#define A
#ifndef A
#define VAL_1 2
#else
#define VAL_1 3
#endif

#define VAL_2 2

unsigned foo() {
 if (VAL_1 != VAL_2)
  {
    return 0;
  }
  else
  {
    return 1;
 }
}


int main() {
  return foo();
}
`
The example is also available on the godbolt: https://godbolt.org/z/e9Y1qP4x9.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE1v4zYQ_TX0ZRBDpGxHPuigJDVQoIceggI9FZQ4kqZLkVp-2El_fUFKcjaLLCDIpmbefLw3Q-k9DQaxZscndnzZyRhG62qUzli9a616r19HhIl89-BQRaOkCQ_4Njv0nqyB2VkVO_Qg4SadITPAjcIIWgb0AYKL5hu0kbSC24gOgQL40UatwNiwZ0Xzu4EwIuCbnGaN0KK2Nwg3C4r6Hh2aAAp7MimHS_aUo7PTLB2qPbyO1uPd445h4hneMcAo5xmNh2BhlFfMqbycEK5SRwQVMZlSONIfYTprehqik4Gs2QMrmsTC1uCABp0MqIA8KxtWNOxUpHf57G10HbLyN1Y2vGRlI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