Package: gcc-12 Version: 12.2.0-14 Severity: normal Tags: upstream Forwarded: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98447
On the following program void f (unsigned long *p, int r, int i) { int b = 64, n = r % 64; while (i >= 0 && b >= 0) { if (b <= n) p[i--] = 1UL << b; b -= n; } } gcc-12 emits the following incorrect warning: $ gcc-12 -fanalyzer -c warn-shiftcount.c warn-shiftcount.c: In function ‘f’: warn-shiftcount.c:8:22: warning: shift by count (‘64’) >= precision of type (‘6’) [-Wanalyzer-shift-count-overflow] 8 | p[i--] = 1UL << b; | ~~~~^~~~ ‘f’: events 1-5 | | 5 | while (i >= 0 && b >= 0) | | ~~~~~~~^~~~~~~~~ | | | | | (1) following ‘true’ branch... | 6 | { | 7 | if (b <= n) | | ~ | | | | | (2) ...to here | | (3) following ‘true’ branch (when ‘b <= n’)... | 8 | p[i--] = 1UL << b; | | ~~~ ~~~~~~~~ | | | | | | | (5) shift by count ‘64’ here | | (4) ...to here | Here, due to the "n = r % 64", one has n <= 63, so that "1UL << b" can be executed only when b <= 63, and the shift is necessarily valid (no overflow). Note: gcc-11 is affected too, but not gcc-10. -- System Information: Debian Release: bookworm/sid APT prefers unstable-debug APT policy: (500, 'unstable-debug'), (500, 'stable-updates'), (500, 'stable-security'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental') merged-usr: no Architecture: amd64 (x86_64) Kernel: Linux 6.1.0-5-amd64 (SMP w/8 CPU threads; PREEMPT) Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE Locale: LANG=POSIX, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages gcc-12 depends on: ii binutils 2.40-2 ii cpp-12 12.2.0-14 ii gcc-12-base 12.2.0-14 ii libc6 2.36-8 ii libcc1-0 12.2.0-14 ii libgcc-12-dev 12.2.0-14 ii libgcc-s1 12.2.0-14 ii libgmp10 2:6.2.1+dfsg1-1.1 ii libisl23 0.25-1 ii libmpc3 1.3.1-1 ii libmpfr6 4.2.0-1 ii libstdc++6 12.2.0-14 ii libzstd1 1.5.4+dfsg2-3 ii zlib1g 1:1.2.13.dfsg-1 Versions of packages gcc-12 recommends: ii libc6-dev 2.36-8 Versions of packages gcc-12 suggests: ii gcc-12-doc 12.2.0-1 ii gcc-12-locales 12.2.0-14 ii gcc-12-multilib 12.2.0-14 -- no debconf information -- Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)