https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118572

            Bug ID: 118572
           Summary: wrong code for expression  ((0x80 & c) != 0) && ((0xc0
                    & c&) ==  0x80))
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter0x44 at disroot dot org
  Target Milestone: ---

bool test(char c)
{
    return (((0x80 & (c&0xff)) != 0) && ((0xc0 & (c&0xff)) ==  0x80));
}

This is getting optimized to:

test(char):
        xor     eax, eax
        ret

And a warning is emitted about the comparison being tautological:
<source>:4:38: warning: comparison is always 0 [-Wtautological-compare]
    4 |     return (((0x80 & (c&0xff)) != 0) && ((0xc0 & (c&0xff)) ==  0x80));
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But it don't think it is (aside from the first half being able to be optimized
out)

https://gcc.godbolt.org/z/T8TM6n833

Found in upstream code:
https://github.com/raysan5/raylib/blob/master/src/rtext.c#L2121-L2138

Reply via email to