Fix more of C/fortran canonical type issues

Richard Biener rguenther@suse.de
Mon Jun 8 13:37:00 GMT 2015


On Mon, 8 Jun 2015, Jan Hubicka wrote:

> > Hi,
> > this patchs makes fortran's C_SIGNED_CHAR and C_SIZE_T interoperable with 
> > signed char and size_t as standard require.  There are two issues here.
> > 
> > First Fortran integers are always signed, but the standard insist on the
> > signed integer to match C size_t that is unsigned (if it was ptrdiff_t, we would
> > be better of) and similarly the standard seems to explicitly state that
> > C_SIGNED_CHAR is interoperable with both signed char and unsigned char.
> > I thus globbed all integer types of precision compatible either with char
> > or size_t to be the same regardless the signedness.
> Hmm, actually there is a note:
>   NOTE 15.8
>   ISO/IEC 9899:1999 specifies that the representations for nonnegative signed
>   integers are the same as the corresponding values of unsigned integers.
>   Because Fortran does not provide direct support for unsigned kinds of integers,
>   the ISO C BINDING module does not make accessible named constant s for their
>   kind type parameter values.  A user can use the signed kinds of integers to
>   interoperate with the unsigned types and  all  their  qualified  versions  as
>   well.   This  has  the  potentially  surprising  side  ect  that  the  C  type
>   unsigned char is interoperable with the type integer with a kind type parameter
>   of C SIGNED CHAR
> 
> This seems to imply that other integer types also should be 
> interoperable regardless of the signedness.  It is true that 
> representation is same for C, but alias sets are not.  Perhaps all of 
> the C BINDING types shall just be dropped to alias set 0? That would 
> also solve the inter-operability of char versus char[1].

Alias-sets of signed and unsigned variants of integer types are the same:

alias_set_type
c_common_get_alias_set (tree t)
{
...
  /* The C standard specifically allows aliasing between signed and
     unsigned variants of the same type.  We treat the signed
     variant as canonical.  */
  if (TREE_CODE (t) == INTEGER_TYPE && TYPE_UNSIGNED (t))
    {
      tree t1 = c_common_signed_type (t);

      /* t1 == t can happen for boolean nodes which are always unsigned.  
*/
      if (t1 != t)
        return get_alias_set (t1);

yes, this should be moved to alias.c ...

Richard.

> I would say that the note is non-normative, so perhaps it can just be 
> ignored, too :)
> 
> Honza
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Dilip Upmanyu, Graham Norton, HRB 21284 (AG Nuernberg)



More information about the Gcc-patches mailing list