public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109820] New: False-positive in tautological-compare
@ 2023-05-11 21:41 ansuelsmth at gmail dot com
  2023-05-11 21:52 ` [Bug c/109820] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: ansuelsmth at gmail dot com @ 2023-05-11 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109820
           Summary: False-positive in tautological-compare
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ansuelsmth at gmail dot com
  Target Milestone: ---

Created attachment 55058
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55058&action=edit
preprocessed file

Hi, while having fun with fixing some compilation warning to enforce WERROR on
kernel linux I faced this interesting false-positive warning.

The simple repro code is this

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <stdint.h>

int main() {
        uint32_t test;

        if (((test >> 4) & 0x15) == 0x9)
                return 1;

        return 0;
}

Compiled with gcc -o test test.c -Wall -Werror

Result in warning
test.c: In function ‘main’:
test.c:10:34: error: bitwise comparison always evaluates to false
[-Werror=tautological-compare]
   10 |         if (((test >> 4) & 0x15) == 0x9)
      |                                  ^~
cc1: all warnings being treated as errors

Decreasing the 0x9 to something like 0x5 mute the warning.
It's either a false positive or a warning that gets not triggered in some
corner case.

I have attached the .i as asked in the guidelines. Don't know if -v is needed.
This is simple gcc installed from ubuntu devel

I also verified that this is present in gcc 13.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/109820] False-positive in tautological-compare
  2023-05-11 21:41 [Bug c/109820] New: False-positive in tautological-compare ansuelsmth at gmail dot com
@ 2023-05-11 21:52 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-11 21:52 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is definitely not a false positive.

        if (((test >> 4) & 0x15) == 0x9)


a & 0x15 will never be equal to 0x9.
The only bits 0x15 and 0x9 share in common is 0x1 (that is 0x9 & 0x15 is 0x1)
so that above bitwise comparison will always be false and that is exactly what
the compiler is warning about.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 21:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11 21:41 [Bug c/109820] New: False-positive in tautological-compare ansuelsmth at gmail dot com
2023-05-11 21:52 ` [Bug c/109820] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).