From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C5E303858298; Fri, 24 Jun 2022 08:59:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5E303858298 From: "ed at catmur dot uk" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106074] New: Spurious Wstringop-overflow for int-to-string with SSE4 Date: Fri, 24 Jun 2022 08:59:40 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ed at catmur dot uk 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 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: Fri, 24 Jun 2022 08:59:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106074 Bug ID: 106074 Summary: Spurious Wstringop-overflow for int-to-string with SSE4 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ed at catmur dot uk Target Milestone: --- Code adapted from https://github.com/capnproto/capnproto/blob/be7a80b4add706ddaeb41689221146b= 86c3e0f5f/c%2B%2B/src/kj/string.c%2B%2B#L157-L203 : auto f(short i) { struct R { char data[6]; } result; bool negative =3D i < 0; unsigned u =3D i; if (negative) u =3D -u; unsigned char reverse[5]; unsigned char* p =3D reverse; if (u =3D=3D 0) *p++ =3D 0; else for (; u > 0; u /=3D 10) *p++ =3D u % 10; char* p2 =3D result.data; if (negative) *p2++ =3D '-'; while (p > reverse) { #ifdef ASSUME if (p2 >=3D (&result.data)[1]) __builtin_unreachable(); #endif *p2++ =3D '0' + *--p; } if (p2 < (&result.data)[1]) *p2 =3D '\0'; return result; } When compiled with -O3 -msse4, from 12.1.0 through 13.0.0 20220619: : In function 'auto f(short int)': :21:11: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 21 | *p2++ =3D '0' + *--p; | ~~~~~~^~~~~~~~~~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ :2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 :2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 :2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 :2:30: note: at offset 7 into destination object 'result' of size 6 2 | struct R { char data[6]; } result; | ^~~~~~ :2:19: note: at offset 6 into destination object 'f(short int)::R::data' of size 6 2 | struct R { char data[6]; } result; | ^~~~ Adding the assumption at line 19 (-DASSUME) works around this.=