From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B34CB3857C67; Sat, 26 Dec 2020 00:51:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B34CB3857C67 From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning Date: Sat, 26 Dec 2020 00:51:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Dec 2020 00:51:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98447 Bug ID: 98447 Summary: incorrect -Wanalyzer-shift-count-overflow warning Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Consider the following code on a platform with a 64-bit unsigned long: void f (unsigned long *p, int r, int i) { int b =3D 63, n =3D r % 16; while (i >=3D 0) { if (n > b) { p[i--] =3D b + 1 >=3D 64 ? 0UL : 1UL << (b + 1); b +=3D 64; } b -=3D n; } } The "1UL << (b + 1)" can be executed only if b + 1 < 64, so that the shift count is always strictly less than 64. But I get the following incorrect warning. zira:~> gcc-snapshot -O2 -fanalyzer -c tst.c tst.c: In function 'f': tst.c:9:38: warning: shift by count ('64') >=3D precision of type ('64') [-Wanalyzer-shift-count-overflow] 9 | p[i--] =3D b + 1 >=3D 64 ? 0UL : 1UL << (b + 1); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ 'f': events 1-5 | | 5 | while (i >=3D 0) | | ~~^~~~ | | | | | (1) following 'true' branch (when 'i >=3D 0')... | 6 | { | 7 | if (n > b) | | ~=20=20 | | | | | (2) ...to here | | (3) following 'true' branch (when 'b < n')... | 8 | { | 9 | p[i--] =3D b + 1 >=3D 64 ? 0UL : 1UL << (b + 1); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | | | (4) ...to here | | (5) shift by count '64' h= ere | with gcc (Debian 20201224-1) 11.0.0 20201224 (experimental) [master revision 085fd2a46e5:21536a75ed4:168be2b3afddd41d4575ed55439231812bc3e7c9] Note: This is a simplified testcase obtained from GNU MPFR's tests/random2.c file, on which I got this issue.=