public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning
@ 2020-12-26  0:51 vincent-gcc at vinc17 dot net
  2020-12-26 16:35 ` [Bug analyzer/98447] " vincent-gcc at vinc17 dot net
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-12-26  0:51 UTC (permalink / raw)
  To: gcc-bugs

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

            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 = 63, n = r % 16;

  while (i >= 0)
    {
      if (n > b)
        {
          p[i--] = b + 1 >= 64 ? 0UL : 1UL << (b + 1);
          b += 64;
        }
      b -= 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') >= precision of type ('64')
[-Wanalyzer-shift-count-overflow]
    9 |           p[i--] = b + 1 >= 64 ? 0UL : 1UL << (b + 1);
      |                    ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
  'f': events 1-5
    |
    |    5 |   while (i >= 0)
    |      |          ~~^~~~
    |      |            |
    |      |            (1) following 'true' branch (when 'i >= 0')...
    |    6 |     {
    |    7 |       if (n > b)
    |      |          ~  
    |      |          |
    |      |          (2) ...to here
    |      |          (3) following 'true' branch (when 'b < n')...
    |    8 |         {
    |    9 |           p[i--] = b + 1 >= 64 ? 0UL : 1UL << (b + 1);
    |      |                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                                      |           |
    |      |                                      |           (4) ...to here
    |      |                                      (5) shift by count '64' here
    |

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.

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

end of thread, other threads:[~2023-02-28 12:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-26  0:51 [Bug analyzer/98447] New: incorrect -Wanalyzer-shift-count-overflow warning vincent-gcc at vinc17 dot net
2020-12-26 16:35 ` [Bug analyzer/98447] " vincent-gcc at vinc17 dot net
2020-12-26 18:17 ` vincent-gcc at vinc17 dot net
2020-12-26 18:21 ` vincent-gcc at vinc17 dot net
2020-12-26 18:47 ` vincent-gcc at vinc17 dot net
2021-01-29 13:50 ` vincent-gcc at vinc17 dot net
2021-04-21 11:54 ` vincent-gcc at vinc17 dot net
2023-02-28 12:59 ` vincent-gcc at vinc17 dot net

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).