On Mon, 11 Sep 2023, Jakub Jelinek wrote: > Hi! > > When discussing PR111369 with Andrew Pinski, I've realized that > I haven't added BITINT_TYPE handling to range_check_type. Right now > (unsigned) max + 1 == (unsigned) min for signed _BitInt,l so I think we > don't need to do the extra hops for BITINT_TYPE (though possibly we don't > need them for INTEGER_TYPE either in the two's complement word and we don't > support anything else, though I really don't know if Ada or some other > FEs don't create weird INTEGER_TYPEs). > And, also I think it is undesirable when being asked for signed_type_for > of unsigned _BitInt(1) (which is valid) to get signed _BitInt(1) (which is > invalid, the standard only allows signed _BitInt(2) and larger), so the > patch returns 1-bit signed INTEGER_TYPE for those cases.
I think the last bit is a bit surprising - do the frontends use signed_or_unsigned_type_for and would they be confused if getting back an INTEGER_TYPE here? The range_check_type bits are OK. For the tree.cc part I think the middle-end can just handle signed 1-bit BITINT fine? > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2023-09-11 Jakub Jelinek <ja...@redhat.com> > > gcc/ > * tree.cc (signed_or_unsigned_type_for): Return INTEGER_TYPE for > signed variant of unsigned _BitInt(1). > * fold-const.cc (range_check_type): Handle BITINT_TYPE like > OFFSET_TYPE. > 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-06 17:50:30.707589026 +0200 > +++ gcc/tree.cc 2023-09-11 16:24:58.749625569 +0200 > @@ -11096,7 +11096,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-06 17:34:24.467254960 +0200 > +++ gcc/c-family/c-common.cc 2023-09-11 16:24:07.873300311 +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) > \ > --- gcc/fold-const.cc.jj 2023-09-11 11:05:47.473728473 +0200 > +++ gcc/fold-const.cc 2023-09-11 16:28:06.052141516 +0200 > @@ -5565,7 +5565,12 @@ range_check_type (tree etype) > else > return NULL_TREE; > } > - else if (POINTER_TYPE_P (etype) || TREE_CODE (etype) == OFFSET_TYPE) > + else if (POINTER_TYPE_P (etype) > + || TREE_CODE (etype) == OFFSET_TYPE > + /* Right now all BITINT_TYPEs satisfy > + (unsigned) max + 1 == (unsigned) min, so no need to verify > + that like for INTEGER_TYPEs. */ > + || TREE_CODE (etype) == BITINT_TYPE) > etype = unsigned_type_for (etype); > return etype; > } > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)