diff mbox series

v2: small _BitInt tweaks

Message ID ZQlMfsN2tNELdv0B@tucnak
State New
Headers show
Series v2: small _BitInt tweaks | expand

Commit Message

Jakub Jelinek Sept. 19, 2023, 7:23 a.m. UTC
Hi!

On Tue, Sep 12, 2023 at 05:27:30PM +0000, Joseph Myers wrote:
> On Tue, 12 Sep 2023, Jakub Jelinek via Gcc-patches wrote:
> 
> > And by ensuring we never create 1-bit signed BITINT_TYPE e.g. the backends
> > don't need to worry about them.
> > 
> > But I admit I don't feel strongly about that.
> > 
> > Joseph, what do you think about this?
> 
> I think it's appropriate to avoid 1-bit signed BITINT_TYPE consistently.

Here is a patch which does that.  In addition to the previously changed two
hunks it also adds a checking assertion that we don't create
signed _BitInt(0), unsigned _BitInt(0) or signed _BitInt(1) types.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-09-18  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree.cc (build_bitint_type): Assert precision is not 0, or
	for signed types 1.
	(signed_or_unsigned_type_for): Return INTEGER_TYPE for signed variant
	of unsigned _BitInt(1).
gcc/c-family/
	* c-common.cc (c_common_signed_or_unsigned_type): Return INTEGER_TYPE
	for signed variant of unsigned _BitInt(1).



	Jakub

Comments

Richard Biener Sept. 19, 2023, 7:33 a.m. UTC | #1
On Tue, 19 Sep 2023, Jakub Jelinek wrote:

> Hi!
> 
> On Tue, Sep 12, 2023 at 05:27:30PM +0000, Joseph Myers wrote:
> > On Tue, 12 Sep 2023, Jakub Jelinek via Gcc-patches wrote:
> > 
> > > And by ensuring we never create 1-bit signed BITINT_TYPE e.g. the backends
> > > don't need to worry about them.
> > > 
> > > But I admit I don't feel strongly about that.
> > > 
> > > Joseph, what do you think about this?
> > 
> > I think it's appropriate to avoid 1-bit signed BITINT_TYPE consistently.
> 
> Here is a patch which does that.  In addition to the previously changed two
> hunks it also adds a checking assertion that we don't create
> signed _BitInt(0), unsigned _BitInt(0) or signed _BitInt(1) types.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2023-09-18  Jakub Jelinek  <jakub@redhat.com>
> 
> gcc/
> 	* tree.cc (build_bitint_type): Assert precision is not 0, or
> 	for signed types 1.
> 	(signed_or_unsigned_type_for): Return INTEGER_TYPE for signed variant
> 	of unsigned _BitInt(1).
> gcc/c-family/
> 	* c-common.cc (c_common_signed_or_unsigned_type): Return INTEGER_TYPE
> 	for signed variant of unsigned _BitInt(1).
> 
> --- gcc/tree.cc.jj	2023-09-11 17:01:17.612714178 +0200
> +++ gcc/tree.cc	2023-09-18 12:36:37.598912717 +0200
> @@ -7179,6 +7179,8 @@ build_bitint_type (unsigned HOST_WIDE_IN
>  {
>    tree itype, ret;
>  
> +  gcc_checking_assert (precision >= 1 + !unsignedp);
> +
>    if (unsignedp)
>      unsignedp = MAX_INT_CACHED_PREC + 1;
>  
> @@ -11096,7 +11098,7 @@ signed_or_unsigned_type_for (int unsigne
>    else
>      return NULL_TREE;
>  
> -  if (TREE_CODE (type) == BITINT_TYPE)
> +  if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
>      return build_bitint_type (bits, unsignedp);
>    return build_nonstandard_integer_type (bits, unsignedp);
>  }
> --- gcc/c-family/c-common.cc.jj	2023-09-11 17:01:17.517715431 +0200
> +++ gcc/c-family/c-common.cc	2023-09-18 12:35:06.829126858 +0200
> @@ -2739,7 +2739,9 @@ c_common_signed_or_unsigned_type (int un
>        || TYPE_UNSIGNED (type) == unsignedp)
>      return type;
>  
> -  if (TREE_CODE (type) == BITINT_TYPE)
> +  if (TREE_CODE (type) == BITINT_TYPE
> +      /* signed _BitInt(1) is invalid, avoid creating that.  */
> +      && (unsignedp || TYPE_PRECISION (type) > 1))
>      return build_bitint_type (TYPE_PRECISION (type), unsignedp);
>  
>  #define TYPE_OK(node)							    \
> 
> 
> 	Jakub
> 
>
diff mbox series

Patch

--- gcc/tree.cc.jj	2023-09-11 17:01:17.612714178 +0200
+++ gcc/tree.cc	2023-09-18 12:36:37.598912717 +0200
@@ -7179,6 +7179,8 @@  build_bitint_type (unsigned HOST_WIDE_IN
 {
   tree itype, ret;
 
+  gcc_checking_assert (precision >= 1 + !unsignedp);
+
   if (unsignedp)
     unsignedp = MAX_INT_CACHED_PREC + 1;
 
@@ -11096,7 +11098,7 @@  signed_or_unsigned_type_for (int unsigne
   else
     return NULL_TREE;
 
-  if (TREE_CODE (type) == BITINT_TYPE)
+  if (TREE_CODE (type) == BITINT_TYPE && (unsignedp || bits > 1))
     return build_bitint_type (bits, unsignedp);
   return build_nonstandard_integer_type (bits, unsignedp);
 }
--- gcc/c-family/c-common.cc.jj	2023-09-11 17:01:17.517715431 +0200
+++ gcc/c-family/c-common.cc	2023-09-18 12:35:06.829126858 +0200
@@ -2739,7 +2739,9 @@  c_common_signed_or_unsigned_type (int un
       || TYPE_UNSIGNED (type) == unsignedp)
     return type;
 
-  if (TREE_CODE (type) == BITINT_TYPE)
+  if (TREE_CODE (type) == BITINT_TYPE
+      /* signed _BitInt(1) is invalid, avoid creating that.  */
+      && (unsignedp || TYPE_PRECISION (type) > 1))
     return build_bitint_type (TYPE_PRECISION (type), unsignedp);
 
 #define TYPE_OK(node)							    \