From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 6F45B3857405; Mon, 14 Mar 2022 10:35:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F45B3857405 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] varasm: Fix ICE in initializer_constant_valid_p_1 X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 473121a7071e99c7953002b8e0103688bd1ba3a3 X-Git-Newrev: b0775d04a58ac8b5a69251ae902c9306f785fcec Message-Id: <20220314103522.6F45B3857405@sourceware.org> Date: Mon, 14 Mar 2022 10:35:22 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2022 10:35:22 -0000 https://gcc.gnu.org/g:b0775d04a58ac8b5a69251ae902c9306f785fcec commit b0775d04a58ac8b5a69251ae902c9306f785fcec Author: Alex Coplan Date: Fri Mar 4 12:36:15 2022 +0000 varasm: Fix ICE in initializer_constant_valid_p_1 This patch fixes ICEs in initializer_constant_valid_p_1 where the initializer value has a capability type. Note that for code such as: char c; char *p = &c - 1; long l = (long)(&c - 1); int i = (int)(&c - 1); even on capability targets, both p and l are valid, but i is invalid. The key observation here is that it doesn't matter if the entire capability fits in the integer type `endtype`, only whether its address value fits in. E.g. for l above we can just emit a normal xword directive with a relocation to obtain the address value. Hence, we change TYPE_PRECISION to TYPE_NONCAP_PRECISION when performing this check on TREE_TYPE (value) in initializer_constant_valid_p_1 for the POINTER_{PLUS,DIFF}_EXPR cases. Diff: --- gcc/varasm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/varasm.c b/gcc/varasm.c index 0301966f484..48a880d4f66 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4868,8 +4868,9 @@ initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache) return NULL_TREE; if (cache && cache[0] == value) return cache[1]; + if (! INTEGRAL_TYPE_P (endtype) - || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value))) + || TYPE_PRECISION (endtype) >= TYPE_NONCAP_PRECISION (TREE_TYPE (value))) { tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE }; tree valid0 @@ -4905,7 +4906,7 @@ initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache) if (cache && cache[0] == value) return cache[1]; if (! INTEGRAL_TYPE_P (endtype) - || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value))) + || TYPE_PRECISION (endtype) >= TYPE_NONCAP_PRECISION (TREE_TYPE (value))) { tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE }; tree valid0