From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3AD393857B83; Wed, 15 Jun 2022 08:32:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AD393857B83 From: "siddhesh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97185] inconsistent builtin elimination for impossible range Date: Wed, 15 Jun 2022 08:32:32 +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: 11.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: siddhesh at gcc dot gnu.org 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: 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, 15 Jun 2022 08:32:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97185 --- Comment #3 from Siddhesh Poyarekar --- (In reply to Martin Sebor from comment #2) > There's a heuristic for ranges of allocation sizes to exclude zero > (size_range_flags) that comes into play here. The actual range isn't > "impossible" in the sense it's necessarily invalid. It just means the > string function call is either a no-op or out of bounds, and so can be > eliminated as an optimization. With the optimization consistently > implemented the warning will also go away (eliminating the calls will > prevent sanitizers from detecting the out of bounds ones, so that might b= e a > consideration). Ahh I see it now, I had missed that it was an 'int'. ISTM that a better id= ea would be to *not* optimize away memcpy and memmove in this case, not the ot= her way around. >=20 > In general, a low > high range denoted an anti-range before Ranger was > introduced (i.e., ~[high, low]). With Ranger it's the corresponding union > of two ranges. Some of the cruft for dealing with anti-ranges is still > around, such as in get_size_range() in pointer-query.cc. The code should= be > migrated to the irange class and the representation probably also updated= to > print something more sensible (e.g., the union [MIN, high) U (low, MAX]; = we > talked about introducing a pretty-printer % directive for ranges to make = the > format consistent across all diagnostics). That makes sense, thanks.=