From: Thomas Koenig Date: Thu, 21 Feb 2019 18:01:41 +0000 (+0000) Subject: re PR fortran/86119 (Intrinsic len has wrong type if used within select type for... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e6644c6fd3c9cf9f6a2fc6315052c953ab363cf;p=gcc.git re PR fortran/86119 (Intrinsic len has wrong type if used within select type for a class(*) string) 2019-02-21 Thomas Koenig PR fortran/86119 * class.c (gfc_get_len_component): Add argument k for kind. If the kind of the resulting expression is not equal to k, convert it. * gfortran.h (gfc_len_component): Adjust prototype. * simplify.c (gfc_simplify_len): Pass kind to gfc_get_len_component. 2019-02-21 Thomas Koenig PR fortran/86119 * gfortran.dg/warn_conversion_11.f90: New test. From-SVN: r269070 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index dd2717cab5a..f8df63db99b 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2019-02-21 Thomas Koenig + + PR fortran/86119 + * class.c (gfc_get_len_component): Add argument k for kind. + If the kind of the resulting expression is not equal to k, + convert it. + * gfortran.h (gfc_len_component): Adjust prototype. + * simplify.c (gfc_simplify_len): Pass kind to + gfc_get_len_component. + 2019-02-20 Martin Liska * gfortran.texi: Change singular to plural. diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index 6c6139b96f5..bcbe6318a4e 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -565,7 +565,7 @@ gfc_intrinsic_hash_value (gfc_typespec *ts) ref to the _len component. */ gfc_expr * -gfc_get_len_component (gfc_expr *e) +gfc_get_len_component (gfc_expr *e, int k) { gfc_expr *ptr; gfc_ref *ref, **last; @@ -590,6 +590,14 @@ gfc_get_len_component (gfc_expr *e) } /* And replace if with a ref to the _len component. */ gfc_add_len_component (ptr); + if (k != ptr->ts.kind) + { + gfc_typespec ts; + gfc_clear_ts (&ts); + ts.type = BT_INTEGER; + ts.kind = k; + gfc_convert_type_warn (ptr, &ts, 2, 0); + } return ptr; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 526897c4170..6c4e839c489 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3479,7 +3479,7 @@ bool gfc_is_class_scalar_expr (gfc_expr *); bool gfc_is_class_container_ref (gfc_expr *e); gfc_expr *gfc_class_initializer (gfc_typespec *, gfc_expr *); unsigned int gfc_hash_value (gfc_symbol *); -gfc_expr *gfc_get_len_component (gfc_expr *e); +gfc_expr *gfc_get_len_component (gfc_expr *e, int); bool gfc_build_class_symbol (gfc_typespec *, symbol_attribute *, gfc_array_spec **); gfc_symbol *gfc_find_derived_vtab (gfc_symbol *); diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 65059c871d2..fa6396bee69 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4474,7 +4474,7 @@ gfc_simplify_len (gfc_expr *e, gfc_expr *kind) /* The expression in assoc->target points to a ref to the _data component of the unlimited polymorphic entity. To get the _len component the last _data ref needs to be stripped and a ref to the _len component added. */ - return gfc_get_len_component (e->symtree->n.sym->assoc->target); + return gfc_get_len_component (e->symtree->n.sym->assoc->target, k); else return NULL; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 138d6034f49..e53731ec08c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-21 Thomas Koenig + + PR fortran/86119 + * gfortran.dg/warn_conversion_11.f90: New test. + 2019-02-21 H.J. Lu PR target/87412 diff --git a/gcc/testsuite/gfortran.dg/warn_conversion_11.f90 b/gcc/testsuite/gfortran.dg/warn_conversion_11.f90 new file mode 100644 index 00000000000..3393e07d31e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/warn_conversion_11.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! { dg-options "-Wconversion" } +! PR 86119 - this used to warn. +program proglen + +implicit none + + class(*), allocatable :: s + integer :: l2 + + allocate(s, source = '123 ') + + select type(s) + type is (character(len=*)) + l2 = len(s) + end select + +end program proglen