From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 204D63858427; Sat, 14 Aug 2021 20:19:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 204D63858427 From: "eggert at cs dot ucla.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/101913] New: -Wstrict-overflow -O3 false alarm on tzdb localtime.c Date: Sat, 14 Aug 2021 20:19:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eggert at cs dot ucla.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned 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 attachments.created 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, 14 Aug 2021 20:19:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101913 Bug ID: 101913 Summary: -Wstrict-overflow -O3 false alarm on tzdb localtime.c Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eggert at cs dot ucla.edu Target Milestone: --- Created attachment 51304 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51304&action=3Dedit -Wstrict-overflow -O3 false alarms I ran into this problem when compiling tzdb localtime.c with gcc (GCC) 11.2= .1 20210728 (Red Hat 11.2.1-1) on x86-64. To reproduce, compile the attached program v.i with: gcc -Wstrict-overflow -O3 -fsanitize=3Dundefined -S v.i The output is: v.i: In function =E2=80=98tzloadbody=E2=80=99: v.i:22:1: warning: assuming signed overflow does not occur when simplifying con\ ditional to constant [-Wstrict-overflow] 22 | tzloadbody (struct state *sp, int leapcnt0, int timecnt0) | ^~~~~~~~~~ v.i:29:25: warning: assuming signed overflow does not occur when simplifying co\ nditional to constant [-Wstrict-overflow] 29 | sp->types[i] =3D at <=3D 0xffffffffu; | ~~~^~~~~~~~~~~~~~ 1. These diagnostics make no sense, since none of the underlined code invol= ves any operations that can overflow. 2. I looked through the code carefully, and none of the arithmetic operatio= ns can possibly overflow. In (result << 8), 'result' is at most 2**32 - 1 and = this fits comfortably into 'long'. -1L << 63 is LONG_MIN. "++i" is executed only when i is less than some other int. timecnt++ and leapcnt++ are executed at most INT_MAX times. prevcorr + 1 is evaluated only when prevcorr < corr, and prevcorr - 1 is evaluated only when prevcorr > corr. 3. The diagnostics vanish if you change MYSTERY from 5 to 4 in the first li= ne. This suggests that GCC is somehow getting confused about whether 'long' has= 8 bytes (which it does on this platform) or 4 bytes.=