re PR fortran/66089 (elemental dependency mishandling when class array are involved)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 10 Mar 2019 10:42:23 +0000 (10:42 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 10 Mar 2019 10:42:23 +0000 (10:42 +0000)
2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/66089
    * trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
    Return false if a scalar tempoary is needed.
    (gfc_walk_variable_expr): Fix up class refs.

2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/66089
    * gfortran.dg/dependency_53.f90: New test.

From-SVN: r269549

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/dependency_53.f90 [new file with mode: 0644]

index d8f5abb1c5d9326b2296d36f46f4be481bd2da8c..8ad4361409163277ba868ee1f9d55d3c58170161 100644 (file)
@@ -1,3 +1,10 @@
+2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/66089
+       * trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
+       Return false if a scalar tempoary is needed.
+       (gfc_walk_variable_expr): Fix up class refs.
+
 2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/87734
index 6192e6830dda1db3f934c9603f4adafd7938af4d..1379426d8e1b8349bb743b6ddf4322c44dacdd69 100644 (file)
@@ -2699,6 +2699,9 @@ gfc_scalar_elemental_arg_saved_as_reference (gfc_ss_info * ss_info)
   if (ss_info->type != GFC_SS_REFERENCE)
     return false;
 
+  if (ss_info->data.scalar.needs_temporary)
+    return false;
+
   /* If the actual argument can be absent (in other words, it can
      be a NULL reference), don't try to evaluate it; pass instead
      the reference directly.  */
@@ -10515,6 +10518,8 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
 {
   gfc_ref *ref;
 
+  gfc_fix_class_refs (expr);
+
   for (ref = expr->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT)
       break;
index 05be09941206002fef1449076fea473b258733db..cb07129671f0b8bb8ad9d1d0e6d404a793ad316c 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/66089
+       * gfortran.dg/dependency_53.f90: New test.
+
 2019-03-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/87734
diff --git a/gcc/testsuite/gfortran.dg/dependency_53.f90 b/gcc/testsuite/gfortran.dg/dependency_53.f90
new file mode 100644 (file)
index 0000000..a45302f
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do run }
+! PR fortran/66089 - used to ICE and, after that ICE was fixed,
+! gave wrong results.
+  type :: t
+    integer :: c
+  end type t
+
+  class(t), dimension(:), allocatable :: b,c
+
+  allocate (b(5), source=t(7))
+  allocate(c(5), source=t(13))
+  c = plus(c(1), b)
+  if (any(c%c /= 20)) stop 1
+  c = t(13)
+  c = plus(b, c(1))
+  if (any(c%c /= 20)) stop 2
+contains
+
+  elemental function plus(lhs, rhs)
+    class(t), intent(in) :: lhs, rhs
+    type(t)             :: plus
+    plus%c = lhs%c + rhs%c
+  end function plus
+
+end