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

--- Comment #4 from Janne Blomqvist <jb at gcc dot gnu.org> ---
(In reply to janus from comment #3)
> (In reply to Dominique d'Humieres from comment #1)
> > Likely revision r256284.
> 
> Certainly.
> 
> For the code in comment 0, -fdump-tree-original shows:
> 
>           l2 = (integer(kind=4)) s._len;
> 
> Apparently the _len component of the class container has kind=8.
> 
> The following patch manages to remove the conversion warning:
> 
> 
> diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
> index 2eae7f0f351..cbc2c72ae3f 100644
> --- a/gcc/fortran/class.c
> +++ b/gcc/fortran/class.c
> @@ -709,7 +709,7 @@ gfc_build_class_symbol (gfc_typespec *ts,
> symbol_attribute *attr,
>           if (!gfc_add_component (fclass, "_len", &c))
>             return false;
>           c->ts.type = BT_INTEGER;
> -         c->ts.kind = gfc_charlen_int_kind;
> +         c->ts.kind = gfc_default_integer_kind;
>           c->attr.access = ACCESS_PRIVATE;
>           c->attr.artificial = 1;
>         }

This is, AFAICS, almost certainly wrong as it breaks the class layout ABI, as
well as handling of long strings.

> However, instead of this, we should rather insert an explicit conversion to
> get rid of the warning, I think.

Yes, LEN(s) is defined to return a value of default kind, so the right approach
is to figure out how to silence the warning.


(In reply to Dominique d'Humieres from comment #1)
> Likely revision r256284.
> 
> kind(len(s)) is 8 in this context, but

To be clear, as mentioned above, without the optional KIND= argument, the LEN
intrinsic is defined to return a value of default kind. So the result of the
above expression should be 4.  Now, you're correct (and perhaps that's what you
intended to say?) that the underlying length value is stored as a kind=C_SIZE_T
variable here.

> character(len=5) :: s
> print *, kind(len(s))
> end
> 
> gives 4.

To clarify, in a situation like this, the length value associated with 's' is
the kind given. So here the length is stored as a default kind integer. For,
say,

character(len=5_16) :: s

the length value is stored as a kind=16 integer.  When calling procedures, or
in class'es etc. where the kind matters for ABI reasons it's converted to
kind=C_SIZE_T

Reply via email to