public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][RFC] Prevent TYPE_PRECISION on VECTOR_TYPEs
@ 2023-06-23  8:26 Richard Biener
  2023-06-23 19:30 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2023-06-23  8:26 UTC (permalink / raw)
  To: gcc-patches

The following makes sure that using TYPE_PRECISION on VECTOR_TYPE
ICEs when tree checking is enabled.  This should avoid wrong-code
in cases like PR110182 and instead ICE.

It also introduces a TYPE_PRECISION_RAW accessor and adjusts
places I found that are eligible to use that.

This patch requires (at least) the series of patches I will
followup this with.  I have to re-bootstrap / test to look
for further fallout (I've picked this up again after some weeks).

Opinions?

Thanks,
Richard.

	* tree.h (TYPE_PRECISION): Check for non-VECTOR_TYPE.
	(TYPE_PRECISION_RAW): Provide raw access to the precision
	field.
	* tree.cc (verify_type_variant): Compare TYPE_PRECISION_RAW.
	(gimple_canonical_types_compatible_p): Likewise.
	* tree-streamer-out.cc (pack_ts_type_common_value_fields):
	Stream TYPE_PRECISION_RAW.
	* tree-streamer-in.cc (unpack_ts_type_common_value_fields):
	Likewise.
	* lto-streamer-out.cc (hash_tree): Hash TYPE_PRECISION_RAW.
---
 gcc/lto-streamer-out.cc  | 2 +-
 gcc/tree-streamer-in.cc  | 2 +-
 gcc/tree-streamer-out.cc | 2 +-
 gcc/tree.cc              | 6 +++---
 gcc/tree.h               | 4 +++-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 5ab2eb4301e..3432dd434e2 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -1373,7 +1373,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map,
       if (AGGREGATE_TYPE_P (t))
 	hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
       hstate.commit_flag ();
-      hstate.add_int (TYPE_PRECISION (t));
+      hstate.add_int (TYPE_PRECISION_RAW (t));
       hstate.add_int (TYPE_ALIGN (t));
       hstate.add_int (TYPE_EMPTY_P (t));
     }
diff --git a/gcc/tree-streamer-in.cc b/gcc/tree-streamer-in.cc
index c803800862c..e6919e463c0 100644
--- a/gcc/tree-streamer-in.cc
+++ b/gcc/tree-streamer-in.cc
@@ -387,7 +387,7 @@ unpack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
     TYPE_TYPELESS_STORAGE (expr) = (unsigned) bp_unpack_value (bp, 1);
   TYPE_EMPTY_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   TYPE_NO_NAMED_ARGS_STDARG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
-  TYPE_PRECISION (expr) = bp_unpack_var_len_unsigned (bp);
+  TYPE_PRECISION_RAW (expr) = bp_unpack_var_len_unsigned (bp);
   SET_TYPE_ALIGN (expr, bp_unpack_var_len_unsigned (bp));
 #ifdef ACCEL_COMPILER
   if (TYPE_ALIGN (expr) > targetm.absolute_biggest_alignment)
diff --git a/gcc/tree-streamer-out.cc b/gcc/tree-streamer-out.cc
index 5751f77273b..719cbeacf99 100644
--- a/gcc/tree-streamer-out.cc
+++ b/gcc/tree-streamer-out.cc
@@ -356,7 +356,7 @@ pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
     bp_pack_value (bp, TYPE_TYPELESS_STORAGE (expr), 1);
   bp_pack_value (bp, TYPE_EMPTY_P (expr), 1);
   bp_pack_value (bp, TYPE_NO_NAMED_ARGS_STDARG_P (expr), 1);
-  bp_pack_var_len_unsigned (bp, TYPE_PRECISION (expr));
+  bp_pack_var_len_unsigned (bp, TYPE_PRECISION_RAW (expr));
   bp_pack_var_len_unsigned (bp, TYPE_ALIGN (expr));
 }
 
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 8e144bc090e..58288efa2e2 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13423,7 +13423,7 @@ verify_type_variant (const_tree t, tree tv)
 	}
       verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
     }
-  verify_variant_match (TYPE_PRECISION);
+  verify_variant_match (TYPE_PRECISION_RAW);
   if (RECORD_OR_UNION_TYPE_P (t))
     verify_variant_match (TYPE_TRANSPARENT_AGGR);
   else if (TREE_CODE (t) == ARRAY_TYPE)
@@ -13701,8 +13701,8 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
       || TREE_CODE (t1) == OFFSET_TYPE
       || POINTER_TYPE_P (t1))
     {
-      /* Can't be the same type if they have different recision.  */
-      if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2))
+      /* Can't be the same type if they have different precision.  */
+      if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
 	return false;
 
       /* In some cases the signed and unsigned types are required to be
diff --git a/gcc/tree.h b/gcc/tree.h
index 1854fe4a7d4..1b791335d38 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2191,7 +2191,9 @@ class auto_suppress_location_wrappers
 #define TYPE_SIZE_UNIT(NODE) (TYPE_CHECK (NODE)->type_common.size_unit)
 #define TYPE_POINTER_TO(NODE) (TYPE_CHECK (NODE)->type_common.pointer_to)
 #define TYPE_REFERENCE_TO(NODE) (TYPE_CHECK (NODE)->type_common.reference_to)
-#define TYPE_PRECISION(NODE) (TYPE_CHECK (NODE)->type_common.precision)
+#define TYPE_PRECISION(NODE) \
+  (TREE_NOT_CHECK (TYPE_CHECK (NODE), VECTOR_TYPE)->type_common.precision)
+#define TYPE_PRECISION_RAW(NODE) (TYPE_CHECK (NODE)->type_common.precision)
 #define TYPE_NAME(NODE) (TYPE_CHECK (NODE)->type_common.name)
 #define TYPE_NEXT_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.next_variant)
 #define TYPE_MAIN_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.main_variant)
-- 
2.35.3

^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [PATCH][RFC] Prevent TYPE_PRECISION on VECTOR_TYPEs
@ 2023-06-23 10:42 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2023-06-23 10:42 UTC (permalink / raw)
  To: gcc-patches

On Fri, 23 Jun 2023, Richard Biener wrote:

> The following makes sure that using TYPE_PRECISION on VECTOR_TYPE
> ICEs when tree checking is enabled.  This should avoid wrong-code
> in cases like PR110182 and instead ICE.
> 
> It also introduces a TYPE_PRECISION_RAW accessor and adjusts
> places I found that are eligible to use that.
> 
> This patch requires (at least) the series of patches I will
> followup this with.  I have to re-bootstrap / test to look
> for further fallout (I've picked this up again after some weeks).
> 
> Opinions?

Bootstrapped on x86_64-unknown-linux-gnu with all lanugages enabled,
but there's still testsuite fallout.

Richard.

> Thanks,
> Richard.
> 
> 	* tree.h (TYPE_PRECISION): Check for non-VECTOR_TYPE.
> 	(TYPE_PRECISION_RAW): Provide raw access to the precision
> 	field.
> 	* tree.cc (verify_type_variant): Compare TYPE_PRECISION_RAW.
> 	(gimple_canonical_types_compatible_p): Likewise.
> 	* tree-streamer-out.cc (pack_ts_type_common_value_fields):
> 	Stream TYPE_PRECISION_RAW.
> 	* tree-streamer-in.cc (unpack_ts_type_common_value_fields):
> 	Likewise.
> 	* lto-streamer-out.cc (hash_tree): Hash TYPE_PRECISION_RAW.
> ---
>  gcc/lto-streamer-out.cc  | 2 +-
>  gcc/tree-streamer-in.cc  | 2 +-
>  gcc/tree-streamer-out.cc | 2 +-
>  gcc/tree.cc              | 6 +++---
>  gcc/tree.h               | 4 +++-
>  5 files changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
> index 5ab2eb4301e..3432dd434e2 100644
> --- a/gcc/lto-streamer-out.cc
> +++ b/gcc/lto-streamer-out.cc
> @@ -1373,7 +1373,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map,
>        if (AGGREGATE_TYPE_P (t))
>  	hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
>        hstate.commit_flag ();
> -      hstate.add_int (TYPE_PRECISION (t));
> +      hstate.add_int (TYPE_PRECISION_RAW (t));
>        hstate.add_int (TYPE_ALIGN (t));
>        hstate.add_int (TYPE_EMPTY_P (t));
>      }
> diff --git a/gcc/tree-streamer-in.cc b/gcc/tree-streamer-in.cc
> index c803800862c..e6919e463c0 100644
> --- a/gcc/tree-streamer-in.cc
> +++ b/gcc/tree-streamer-in.cc
> @@ -387,7 +387,7 @@ unpack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
>      TYPE_TYPELESS_STORAGE (expr) = (unsigned) bp_unpack_value (bp, 1);
>    TYPE_EMPTY_P (expr) = (unsigned) bp_unpack_value (bp, 1);
>    TYPE_NO_NAMED_ARGS_STDARG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
> -  TYPE_PRECISION (expr) = bp_unpack_var_len_unsigned (bp);
> +  TYPE_PRECISION_RAW (expr) = bp_unpack_var_len_unsigned (bp);
>    SET_TYPE_ALIGN (expr, bp_unpack_var_len_unsigned (bp));
>  #ifdef ACCEL_COMPILER
>    if (TYPE_ALIGN (expr) > targetm.absolute_biggest_alignment)
> diff --git a/gcc/tree-streamer-out.cc b/gcc/tree-streamer-out.cc
> index 5751f77273b..719cbeacf99 100644
> --- a/gcc/tree-streamer-out.cc
> +++ b/gcc/tree-streamer-out.cc
> @@ -356,7 +356,7 @@ pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
>      bp_pack_value (bp, TYPE_TYPELESS_STORAGE (expr), 1);
>    bp_pack_value (bp, TYPE_EMPTY_P (expr), 1);
>    bp_pack_value (bp, TYPE_NO_NAMED_ARGS_STDARG_P (expr), 1);
> -  bp_pack_var_len_unsigned (bp, TYPE_PRECISION (expr));
> +  bp_pack_var_len_unsigned (bp, TYPE_PRECISION_RAW (expr));
>    bp_pack_var_len_unsigned (bp, TYPE_ALIGN (expr));
>  }
>  
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index 8e144bc090e..58288efa2e2 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -13423,7 +13423,7 @@ verify_type_variant (const_tree t, tree tv)
>  	}
>        verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
>      }
> -  verify_variant_match (TYPE_PRECISION);
> +  verify_variant_match (TYPE_PRECISION_RAW);
>    if (RECORD_OR_UNION_TYPE_P (t))
>      verify_variant_match (TYPE_TRANSPARENT_AGGR);
>    else if (TREE_CODE (t) == ARRAY_TYPE)
> @@ -13701,8 +13701,8 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
>        || TREE_CODE (t1) == OFFSET_TYPE
>        || POINTER_TYPE_P (t1))
>      {
> -      /* Can't be the same type if they have different recision.  */
> -      if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2))
> +      /* Can't be the same type if they have different precision.  */
> +      if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
>  	return false;
>  
>        /* In some cases the signed and unsigned types are required to be
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 1854fe4a7d4..1b791335d38 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -2191,7 +2191,9 @@ class auto_suppress_location_wrappers
>  #define TYPE_SIZE_UNIT(NODE) (TYPE_CHECK (NODE)->type_common.size_unit)
>  #define TYPE_POINTER_TO(NODE) (TYPE_CHECK (NODE)->type_common.pointer_to)
>  #define TYPE_REFERENCE_TO(NODE) (TYPE_CHECK (NODE)->type_common.reference_to)
> -#define TYPE_PRECISION(NODE) (TYPE_CHECK (NODE)->type_common.precision)
> +#define TYPE_PRECISION(NODE) \
> +  (TREE_NOT_CHECK (TYPE_CHECK (NODE), VECTOR_TYPE)->type_common.precision)
> +#define TYPE_PRECISION_RAW(NODE) (TYPE_CHECK (NODE)->type_common.precision)
>  #define TYPE_NAME(NODE) (TYPE_CHECK (NODE)->type_common.name)
>  #define TYPE_NEXT_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.next_variant)
>  #define TYPE_MAIN_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.main_variant)
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-23 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23  8:26 [PATCH][RFC] Prevent TYPE_PRECISION on VECTOR_TYPEs Richard Biener
2023-06-23 19:30 ` Jeff Law
2023-06-23 10:42 Richard Biener

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).