From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B6D13387089F; Thu, 11 May 2023 12:22:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6D13387089F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683807730; bh=PhgWwtHchmNi4yuXT4Z/Bz97m+QuFxL5ht+w+i08RYA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QF+5lFs2EpQ6Nuto2liw3pPiIq6d4j3f26Pog48Uauv6HvQqpmURUiczWY6QEKkwy uGW2QO6feBl/V63MLc/VPfbiiyfRa6BBCFdHRN2J7Jk5LJbchB0LN+1Y/0PDuiiy+E ZlrvHKqWDEmnfMxzO39mdur6UfaWQJ6jM5m45ajk= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109791] -Wstringop-overflow warning with -O3 and _GLIBCXX_USE_CXX11_ABI=0 Date: Thu, 11 May 2023 12:22:10 +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.1.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109791 --- Comment #9 from Richard Biener --- So the first pass that makes things difficult is reassoc which transforms _51 =3D (unsigned long) &MEM [(void *)&str + 2B]; _4 =3D (unsigned long) __i_44; _65 =3D _51 - _4; _48 =3D _65 + 18446744073709551615; _46 =3D _48 > 13; if (_46 !=3D 0) to _51 =3D (unsigned long) &MEM [(void *)&str + 2B]; _4 =3D (unsigned long) __i_44; _12 =3D -_4; _119 =3D _51 + 18446744073709551615; _48 =3D _119 - _4; _46 =3D _48 > 13; if (_46 !=3D 0) (also leaving garbage around). That's probably because of the PHI biasing and __i_44 being defined by a PHI. niter analysis produces # of iterations (((unsigned long) &MEM [(void *)&str + 2B] - (unsigned long) __i_44) + 18446744073709551615) / 2, bounded by 9223372036854775807 but doesn't expand __i_44 (not sure if we'd fold the thing then). The gimplifier folds stmts w/o following SSA edges when we eventually re-gimplify those expressions for insertion. If we expand offsetting of invariant bases we get instead # of iterations ((unsigned long) &MEM [(void *)&str + 2B] - (unsi= gned long) (&str + (_69 + 1))) / 2, bounded by 9223372036854775807 but that's still not simplified. I think ptr_difference_const should handle this - of course the difference here isn't const... /* Try folding difference of addresses. */=20 (simplify (minus (convert ADDR_EXPR@0) (convert @1)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (with { poly_int64 diff; }=20 (if (ptr_difference_const (@0, @1, &diff)) { build_int_cst_type (type, diff); })))) (simplify=20 (minus (convert @0) (convert ADDR_EXPR@1)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (with { poly_int64 diff; } (if (ptr_difference_const (@0, @1, &diff)) { build_int_cst_type (type, diff); }))))=20 it works fine when adding (simplify (minus (convert ADDR_EXPR@0) (convert (pointer_plus @1 @2))) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (with { poly_int64 diff; } (if (ptr_difference_const (@0, @1, &diff)) (minus { build_int_cst_type (type, diff); } (convert @2)))))) then we get # of iterations (1 - (unsigned long) _69) / 2, bounded by 9223372036854775807 and the diagnostic is gone.=