From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2C00E3858414; Tue, 30 Nov 2021 17:56:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C00E3858414 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103483] context-sensitive ranges change triggers stringop-overread Date: Tue, 30 Nov 2021 17:56:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic, missed-optimization 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: component keywords cc 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: Tue, 30 Nov 2021 17:56:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103483 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c++ |middle-end Keywords| |missed-optimization CC| |msebor at gcc dot gnu.org --- Comment #3 from Martin Sebor --- The warning is only issued at -O1. It's based on the statement in the IL a= nd the values or ranges of its arguments. In this case the IL and the argument values are below: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 6 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Imports: _1 d_6(D)=20=20 Exports: _1 d_6(D)=20=20 _1 sizetype [0, 0][2, 15] [local count: 362271902]: if (_1 =3D=3D 0) goto ; [100.00%] else goto ; [0.00%] 6->8 (T) _1 : sizetype [0, 0] 6->7 (F) _1 : sizetype [2, 15] >>> _1 > 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 7 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [local count: 346397698]: # _2 =3D PHI <&s.D.26133._M_local_buf(6), _19(3)> __builtin_memcpy (_2, &buffer, _1); <<< -Wstringop-overread The memcpy() call reads between 2 and 15 bytes from the one-byte buffer. So the warning code is working as designed. The problem is that at -O1 the co= de isn't optimized sufficiently to discover that the memcpy call only reads 1 = byte (the function call isn't inlined and so the constant argument isn't propaga= ted into the call).=20 GCC 11 doesn't warn because it's unable to determine the range of the last memcpy() argument. Thanks to the Ranger improvements GCC 12 is able to do better. In some cases this should improve the S/N ratio of the middle end diagnostics that depend on ranges. Unfortunately, in others like this one where other optimizations are disabled it can make things worse.=