public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 86119, spurios warning for len(classtype) with -Wconversion
@ 2019-02-19 21:49 Thomas Koenig
  2019-02-20 21:03 ` Janne Blomqvist
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2019-02-19 21:49 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

Hello world,

the attached patch fixes the 8/9 regression by inserting the conversion
at the right place.  Regression-tested. OK for trunk, and for 8 when it
re-opens?

Regards

	Thomas

2019-02-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/86110
         * 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-19  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/86110
         * gfortran.dg/warn_conversion_11.f90: New test.

[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1967 bytes --]

Index: class.c
===================================================================
--- class.c	(Revision 268968)
+++ class.c	(Arbeitskopie)
@@ -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_expr *
     }
   /* 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;
 }
 
Index: gfortran.h
===================================================================
--- gfortran.h	(Revision 268968)
+++ gfortran.h	(Arbeitskopie)
@@ -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 *);
Index: simplify.c
===================================================================
--- simplify.c	(Revision 268968)
+++ simplify.c	(Arbeitskopie)
@@ -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;
 }

[-- Attachment #3: warn_conversion_11.f90 --]
[-- Type: text/x-fortran, Size: 299 bytes --]

! { 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch, fortran] Fix PR 86119, spurios warning for len(classtype) with -Wconversion
  2019-02-19 21:49 [patch, fortran] Fix PR 86119, spurios warning for len(classtype) with -Wconversion Thomas Koenig
@ 2019-02-20 21:03 ` Janne Blomqvist
  0 siblings, 0 replies; 2+ messages in thread
From: Janne Blomqvist @ 2019-02-20 21:03 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Tue, Feb 19, 2019 at 11:49 PM Thomas Koenig <tkoenig@netcologne.de> wrote:
>
> Hello world,
>
> the attached patch fixes the 8/9 regression by inserting the conversion
> at the right place.  Regression-tested. OK for trunk, and for 8 when it
> re-opens?

Ok, except that the PR numbers in the ChangeLog entries are wrong.
Thanks for the patch!


-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-20 21:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 21:49 [patch, fortran] Fix PR 86119, spurios warning for len(classtype) with -Wconversion Thomas Koenig
2019-02-20 21:03 ` Janne Blomqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).