From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5DE183858010; Thu, 2 Dec 2021 21:53:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DE183858010 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103534] [12 regression] Spurious -Wstringop-overflow warning with std::string concatencation Date: Thu, 02 Dec 2021 21:53:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: alias, diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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: keywords Message-ID: In-Reply-To: References: 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, 02 Dec 2021 21:53:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103534 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |alias, missed-optimization --- Comment #2 from Andrew Pinski --- Note there is one missing optimization: D.42086._M_string_length =3D 0; MEM[(char_type &)&D.42086 + 16] =3D 0; MEM[(struct basic_string *)&D.41925] =3D{v} {CLOBBER}; MEM[(struct _Alloc_hider *)&D.41925] =3D{v} {CLOBBER}; MEM[(struct _Alloc_hider *)&D.41925]._M_p =3D &D.41925.D.33308._M_local_b= uf; _69 =3D operator new (17); [local count: 1003797485]: D.41925._M_dataplus._M_p =3D _69; D.41925.D.33308._M_allocated_capacity =3D 16; __builtin_memcpy (_69, "1234567890123456", 16); D.41925._M_string_length =3D 16; MEM[(char_type &)_69 + 16] =3D 0; _75 =3D D.42086._M_string_length; __size_76 =3D _75 + 16; pretmp_56 =3D D.42086._M_dataplus._M_p; if (__size_76 > 16) goto ; [67.00%] else goto ; [33.00%] This might be related to that GCC does not handle the operator new better. Obvious if that missed optimization is fixed, then the warning will be gone. I also noticed that with -std=3Dc++17 (or before), the constructor for std::string is not inlined fully for both std::string objects which avoids = the false positive. This is another case where it is a "maybe" exceeds maximum object size and = we need to come up with a solution for it.=