http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51842

--- Comment #7 from Janne Blomqvist <jb at gcc dot gnu.org> 2012-01-13 11:44:05 
UTC ---
(In reply to comment #6)
> (In reply to comment #5)
> > Yes, and no. It is perhaps a better match for the current frontend logic of
> > choosing a type equal to the pointer size, but semantically ptrdiff_t is the
> > better choice for array indexing. 
> 
> OK. But then the logical step is to change the FE

Yes. I didn't do it as part of my patch back in April last year, because I
wasn't sure how to properly do it, and I didn't worry about supporting targets
where sizeof(void*) != sizeof(ptrdiff_t).

> - how about something like
> the following?
> 
> --- a/gcc/fortran/trans-types.c
> +++ b/gcc/fortran/trans-types.c
> @@ -576,10 +576,7 @@ gfc_init_kinds (void)
>    gfc_default_character_kind = gfc_character_kinds[0].kind;
>    gfc_character_storage_size = gfc_default_character_kind * 8;
> 
> -  /* Choose the integer kind the same size as "void*" for our index kind.  */
> -  gfc_index_integer_kind = POINTER_SIZE / 8;
> -  /* Pick a kind the same size as the C "int" type.  */
> -  gfc_c_int_kind = INT_TYPE_SIZE / 8;
> +  gfc_index_integer_kind = get_int_kind_from_name (PTRDIFF_TYPE);

(Well, you probably don't want to remove the assignment to gfc_c_int_kind.)

But otherwise, if this works, it looks ok. FWIW in c-family/c-common.c there is

ptrdiff_type_node
    = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));

So if the above patch + our definition for the array index type node

gfc_array_index_type = gfc_get_int_type (gfc_index_integer_kind);

accomplishes the same thing, it looks Ok.

Reply via email to