From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CFAED3858D35; Wed, 8 Dec 2021 23:30:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFAED3858D35 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103332] [12 Regression] Spurious -Wstringop-overflow on string concatenation in libstdc++ tests Date: Wed, 08 Dec 2021 23:30:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor 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: see_also short_desc cf_known_to_fail 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: Wed, 08 Dec 2021 23:30:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103332 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=3D103534 Summary|Spurious |[12 Regression] Spurious |-Wstringop-overflow |-Wstringop-overflow on |warnings in libstdc++ tests |string concatenation in | |libstdc++ tests Known to fail| |12.0 --- Comment #5 from Martin Sebor --- The first warning is for the invalid memcpy() call below: struct string D.35215; ... [local count: 1073312331]: D.35215._M_string_length =3D 16; _62 =3D D.35215._M_dataplus._M_p; MEM[(char_type &)_62 + 16] =3D 0; D.35222 =3D{v} {CLOBBER}; MEM[(struct _Alloc_hider *)&D.35222] =3D{v} {CLOBBER}; MEM[(struct _Alloc_hider *)&D.35222]._M_p =3D &D.35222.D.28102._M_local_b= uf; if (&MEM [(void *)&D.35215 + 16B] =3D=3D _62) goto ; [30.00%] else goto ; [70.00%] [local count: 157390518]: __builtin_memcpy (&D.35222.D.28102._M_local_buf, &MEM [(= void *)&D.35215 + 16B], 17); goto ; [100.00%] sizeof std::string::_M_local_buf is 16 but the call writes 17 bytes into it= , so the call is invalid. I only see the warning at -O1 (and with -D_GLIBCXX_DEBUG). It also goes aw= ay if I force std::string::_M_mutate to be inlined. _M_mutate allocates the dynamic string so with it inlined GCC can determine that the local buffer i= s no longer used and eliminate the invalid call. So as in the other cases we ha= ve seen recently, this false positive is due to some optimizer limitations cau= sed by the combination of -O1 and a decision to throttle inlining. The second warning is due to the same issue. It too goes away with more aggressive inlining (on x86_64 setting -finline-limit=3D200 avoids it).=