public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] varasm: Fix ICE in initializer_constant_valid_p_1
@ 2022-03-14 10:35 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-03-14 10:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b0775d04a58ac8b5a69251ae902c9306f785fcec

commit b0775d04a58ac8b5a69251ae902c9306f785fcec
Author: Alex Coplan <alex.coplan@arm.com>
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-14 10:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 10:35 [gcc(refs/vendors/ARM/heads/morello)] varasm: Fix ICE in initializer_constant_valid_p_1 Matthew Malcomson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).