From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CEBFD385AC2D; Fri, 21 Jan 2022 17:16:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEBFD385AC2D From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104165] [12 Regression] -Warray-bounds for unreachable code inlined from std::sort() Date: Fri, 21 Jan 2022 17:16:43 +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: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cc cf_reconfirmed_on blocked short_desc everconfirmed 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: Fri, 21 Jan 2022 17:16:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104165 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW CC| |msebor at gcc dot gnu.org Last reconfirmed| |2022-01-21 Blocks| |56456 Summary|[12 Regression] Incorrectly |[12 Regression] |identifying array bounds |-Warray-bounds for |with -O2 |unreachable code inlined |-Werror=3Darray-bounds |from std::sort() Ever confirmed|0 |1 --- Comment #1 from Martin Sebor --- The warning triggers for the out of bounds pointer addition in &f.148 + 64 = for an array of 16 chars: int foo (int n) { unsigned char f.148[16]; ... [local count: 116203857]: _25 =3D ASSERT_EXPR <_15, _15 !=3D &f.148>; _6 =3D (signed long) _14; _19 =3D _6 /[ex] 4; __n.3_20 =3D (long unsigned int) _19; _21 =3D __builtin_clzl (__n.3_20); _22 =3D 63 - _21; _23 =3D (long int) _22; _24 =3D _23 * 2; std::__introsort_loop > > (&f.148, _25, _24, __comp); if (_14 > 64) goto ; [50.00%] else goto ; [50.00%] [local count: 58101929]: std::__insertion_sort.constprop (&f.148, &MEM [(void *)&f.148 + 64B]); <<< -Warray-bounds goto ; [100.00%] The basic block is removed later, in CCP3, as unreachable: Removing basic block 8 ;; basic block 8, loop depth 0 ;; pred:=20=20=20=20=20=20 std::__insertion_sort.constprop (&f.148, &MEM [(void *)&f.= 148 + 64B]); if (&MEM [(void *)&f.148 + 64B] !=3D _15) goto ; [89.00%] else goto ; [11.00%] ;; succ: 9 ;; 13 The warning runs too early to benefit from the subsequent simplification. = This is one instance of a false positive that something like __builtin_warning() would cure. GCC 11 emits (and eliminates) the same invalid expression but the warning is suppressed because in GCC 11 -Warray-bounds wasn't issued code inlined from system headers. That's a GCC 12 change. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56456 [Bug 56456] [meta-bug] bogus/missing -Warray-bounds=