public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95141] New: Incorrect integer overflow warning message for bitand expression
@ 2020-05-14 19:51 yadongh at vt dot edu
  2020-05-15  7:30 ` [Bug c/95141] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: yadongh at vt dot edu @ 2020-05-14 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95141
           Summary: Incorrect integer overflow warning message for bitand
                    expression
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yadongh at vt dot edu
  Target Milestone: ---

C code:
#include <stdint.h>

uint64_t test(uint8_t IA1)
{
  return (uint8_t)(IA1 & 158) & 1UL;
}


Command:
gcc -c test.c


Warning message:
test.c: In function ‘test’:
test.c:5:31: warning: integer overflow in expression ‘(long unsigned int)IA1 &
158 & 1’ of type ‘long unsigned int’ results in ‘0’ [-Woverflow]
   return (uint8_t)(IA1 & 158) & 1UL;
          ~~~~~~~~~~~~~~~~~~~~~^~~~~


gcc -v output:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6'
--with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-
major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu-
--enable-shared --enable-linker-build-id --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --libdir=/usr/lib --enab
le-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-pl
ugin --enable-default-pie --with-system-zlib --with-target-system-zlib
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-mult
ilib --with-tune=generic --enable-offload-targets=nvptx-none
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)

Note that I find this reproducible starting from GCC 7.1 to 10.1 (on GodBolt).


Platform:
Debian 10 Linux


Problem statement:
There are a lot of explicit/implicit integer type casts here, but in no way I
think integer overflow can happen. Note that essentially we are returning zero
here as 158 & 1 is just zero.
Some other interesting observations:
(uint8_t)(IA1 & 159) & 1UL;      --- No Warning
(uint8_t)(IA1 & 158U) & 1UL;     --- No Warning
(uint8_t)(IA1 & 254) & 1UL;      --- Warning
(uint8_t)(IA1 & 2) & 1UL;        --- No Warning

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

end of thread, other threads:[~2022-05-27  8:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 19:51 [Bug c/95141] New: Incorrect integer overflow warning message for bitand expression yadongh at vt dot edu
2020-05-15  7:30 ` [Bug c/95141] [8/9/10/11 Regression] " jakub at gcc dot gnu.org
2020-05-15  9:02 ` rguenth at gcc dot gnu.org
2020-05-18 13:28 ` rguenth at gcc dot gnu.org
2020-05-20  7:40 ` cvs-commit at gcc dot gnu.org
2020-05-20  7:42 ` [Bug c/95141] [8/9/10 " rguenth at gcc dot gnu.org
2020-06-23 11:06 ` cvs-commit at gcc dot gnu.org
2020-06-23 11:08 ` [Bug c/95141] [8/9 " rguenth at gcc dot gnu.org
2021-05-14  9:53 ` [Bug c/95141] [9 " jakub at gcc dot gnu.org
2021-06-01  8:17 ` rguenth at gcc dot gnu.org
2022-05-27  8:52 ` rguenth 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).