This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] Fix PR 83540


Hello world,

this rather self-explanatory patch makes sure we don't get an error
using reallocation on assignment for inlining matmul when
we don't have reallocation on assignment.

Regression-tested. OK for trunk?

Regards

	Thomas

2017-12-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/83540
        * frontend-passes.c (create_var): If an array to be created
        has unknown size and -fno-realloc-lhs is in effect,
        return NULL.

2017-12-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/83540
        * gfortran.dg/inline_matmul_20.f90: New test.
Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 255788)
+++ frontend-passes.c	(Arbeitskopie)
@@ -720,6 +720,11 @@ create_var (gfc_expr * e, const char *vname)
   if (e->expr_type == EXPR_CONSTANT || is_fe_temp (e))
     return gfc_copy_expr (e);
 
+  /* Creation of an array of unknown size requires realloc on assignment.
+     If that is not possible, just return NULL.  */
+  if (flag_realloc_lhs == 0 && e->rank > 0 && e->shape == NULL)
+    return NULL;
+
   ns = insert_block ();
 
   if (vname)
! { dg-do  run }
! { dg-additional-options "-fno-realloc-lhs -ffrontend-optimize" }
! This used to segfault at runtime.
! Original test case by Harald Anlauf.
program gfcbug142
  implicit none
  real, allocatable :: b(:,:)
  integer :: n = 5
  character(len=20) :: line
  allocate (b(n,n))
  call random_number (b)
  write (unit=line,fmt='(2I5)') shape (matmul (b, transpose (b)))
  if (line /= '    5    5') call abort
end program gfcbug142

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]