From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 39A863858D1E; Tue, 29 Nov 2022 14:29:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39A863858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669732158; bh=rr0mEUw/C8MZ/iO/wSL5CsiHNgE7eeis/wV47AH+t2o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=juEdnwlMOWMqcV+o592DMIQzVx9e+cZhB/JvDAE5ZqZjzcIVasHvbJTClOVLwIB2m 2K6kMmGRq9mubMObVJx5zPOnX/opNslnDfg3D72OywrrX72uyed9wg6/lYj9xg6Riw 3KXCsfNXBPTUC2uYNJIGP6ck4iom2mAteoOK63+A= From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107898] [11/12 Regression] ICE in irange_intersect, at value-range.cc:1640 Date: Tue, 29 Nov 2022 14:29:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107898 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #3 from Andrew Macleod --- (In reply to Richard Biener from comment #1) > I'm not sure why we have to require compatible ranges on intersection > of irange though? Since we don't have anti-ranges there's no implicit Its doesnt require compatible types, it requires compatible precisions. From gimple-range-fold.h: static inline bool range_compatible_p (tree type1, tree type2) { // types_compatible_p requires conversion in both directions to be useles= s. // GIMPLE only requires a cast one way in order to be compatible. // Ranges really only need the sign and precision to be the same. return (TYPE_PRECISION (type1) =3D=3D TYPE_PRECISION (type2) && TYPE_SIGN (type1) =3D=3D TYPE_SIGN (type2));=20 } >=20 > Unfortunately there's no conversion operator or operator> for irange, > we just want to ask if (r > max_size) (and have max_size converted to > the type of r with saturation). You can cast an irange to another type using range_cast. ie something like diff --git a/gcc/gimple-ssa-warn-alloca.cc b/gcc/gimple-ssa-warn-alloca.cc index 83a241a3a4b..0502c433f93 100644 --- a/gcc/gimple-ssa-warn-alloca.cc +++ b/gcc/gimple-ssa-warn-alloca.cc @@ -225,6 +225,8 @@ alloca_call_type (gimple *stmt, bool is_vla) build_int_cst (size_type_node, max_size), VR_ANTI_RANGE); + if (!types_compatible_p (r.type (), invalid_range.type ())) + range_cast (invalid_range, r.type ()); r.intersect (invalid_range); if (r.undefined_p ()) return alloca_type_and_limit (ALLOCA_OK) We decided to force something like this to be explicit by the caller rather than make assumptions in intersect/union and silently do conversions. We've caught a number of bugs along the way because of this. Another option would be to simply create the invalid_range with the same ty= pe upfront instead of assuming size_type_node. ie: @@ -221,8 +221,8 @@ alloca_call_type (gimple *stmt, bool is_vla) && !r.varying_p ()) { // The invalid bits are anything outside of [0, MAX_SIZE]. - int_range<2> invalid_range (build_int_cst (size_type_node, 0), - build_int_cst (size_type_node, max_size), + int_range<2> invalid_range (build_int_cst (r.type (), 0), + build_int_cst (r.type (), max_size), VR_ANTI_RANGE); r.intersect (invalid_range); As long as r.type () is irange::supports_p (r.type ())=