From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A4522385481B; Thu, 29 Oct 2020 12:42:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4522385481B From: "walter.gcc at wjd dot nu" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97628] New: format truncation false positive for O1 and mtune=nocona Date: Thu, 29 Oct 2020 12:42:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: walter.gcc at wjd dot nu 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: Thu, 29 Oct 2020 12:42:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97628 Bug ID: 97628 Summary: format truncation false positive for O1 and mtune=3Dnocona Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: walter.gcc at wjd dot nu Target Milestone: --- Created attachment 49468 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49468&action=3Dedit trimmed down problem from Asterisk say.c Per the discussion here: https://gerrit.asterisk.org/c/asterisk/+/14501 I believe there is a bug in gcc 9 where it falsely reports: warning: =E2=80=98%d=E2=80=99 directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Wformat-truncation=3D] See the attached example, it only triggers when: - optimization is 1 or higher - arch tuning is set to nocona Example: $ gcc -O1 -mtune=3Dnocona -S -Wall say2.c say2.c: In function =E2=80=98ast_say_number_full_zh=E2=80=99: say2.c:37:32: warning: =E2=80=98%d=E2=80=99 directive output may be truncat= ed writing between 1 and 11 bytes into a region of size 10 [-Wformat-truncation=3D] 37 | snprintf(buf, 10, "%d", num); | ^~ say2.c:37:31: note: directive argument in the range [-2147483648, 9] ... But when omitting either -O1 or -mtune=3Dnocona we do not get this warning. And if you read the code, you would see that at line 37, num cannot be nega= tive (because it would've hit a different if-branch). gcc version is the Ubuntu/Focal one: $ gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Cheers, Walter Doekes OSSO B.V.=