https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78429

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Eric Botcazou from comment #8)
> > where -1 no longer "fits" bool even though it should.  So
> > 
> >   /* Short-circuit boolean types since various transformations assume that
> >      they can only take values 0 and 1.  */
> >   if (TREE_CODE (type) == BOOLEAN_TYPE)
> >     return eq_p (x, 0) || eq_p (x, 1);
> > 
> > is wrong and should use eq_p (x, -1) instead as bool is signed?  The
> > int_fits_type_p function is likely wrong as well (uses integer_onep).
> 
> Standard boolean types as unsigned though, not signed:
> 
> Index: tree.c
> ===================================================================
> --- tree.c      (revision 242632)
> +++ tree.c      (working copy)
> @@ -8218,7 +8218,7 @@ build_nonstandard_boolean_type (unsigned
>  
>    type = make_node (BOOLEAN_TYPE);
>    TYPE_PRECISION (type) = precision;
> -  fixup_signed_type (type);
> +  fixup_unsigned_type (type);
>  
>    if (precision <= MAX_INT_CACHED_PREC)
>      nonstandard_boolean_type_cache[precision] = type;
> 
> fixes the ICE.

fortran does

static tree
gfc_build_logical_type (gfc_logical_info *info)
{
  int bit_size = info->bit_size;
  tree new_type;

  if (bit_size == BOOL_TYPE_SIZE)
    {
      info->c_bool = 1;
      return boolean_type_node;
    }

  new_type = make_unsigned_type (bit_size);
  TREE_SET_CODE (new_type, BOOLEAN_TYPE);
  TYPE_MAX_VALUE (new_type) = build_int_cst (new_type, 1);
  TYPE_PRECISION (new_type) = 1;

note that the vectorizer emits code to widen the boolean types expecting
sign-extension of vector truth (-1).  That matches what the RTL code gen
ends up doing semantics-wise.

It has been changed by

2015-11-09  Ilya Enkovich  <enkovich....@gmail.com>

        * optabs.c (expand_vec_cond_expr): Always get sign from type.
        * tree.c (wide_int_to_tree): Support negative values for boolean.
        (build_nonstandard_boolean_type): Use signed type for booleans.

thus the signedness is wanted (so is the precision).  The issues arise
once we are extracting a vector element and performing the (_Bool) cast...

Reply via email to