[C++ PATCH] P0258R2 - add __has_unique_object_representations

Jason Merrill jason@redhat.com
Thu Oct 6 02:43:00 GMT 2016


On Wed, Oct 5, 2016 at 4:02 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> +    case INTEGER_TYPE:
> +      return TYPE_PRECISION (t) == GET_MODE_PRECISION (TYPE_MODE (t));
> +
> +    case BOOLEAN_TYPE:
> +      /* For bool values other than 0 and 1 should only appear with
> +        undefined behavior.  */
> +      return true;
> +
> +    case ENUMERAL_TYPE:
> +      return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t));

I would think that we want the same answer for bool and enums: Either
the whole type size participates in the value representation, but only
certain values have defined behavior (so we should return true), or
only certain bits participate in the value representation (so we
should return false).  This is a question for the committee, but I'm
inclined to use the INTEGER_TYPE code for BOOLEAN_TYPE and
ENUMERAL_TYPE as well, since we don't mask off the other bits when
loading one of these types.

> +    case POINTER_TYPE:
> +    case REFERENCE_TYPE:
> +      return true;

Is this true for all targets?  Aren't there some pointer modes that
only take up part of a word?

> +    else if (DECL_C_BIT_FIELD (field))
> +      {
> +       tree btype = DECL_BIT_FIELD_TYPE (field);
> +       if (!type_has_unique_obj_representations (btype))
> +         return false;
> +      }

C++ allows a bit-field to be larger than the type needs, in which case
we should return false.

Jason



More information about the Gcc-patches mailing list