Dear All,

The fix to eliminate this ICE is trivial.

Bootstrapped and regtested on FC21/x86_64 - OK for 5 to 7 branches?

Cheers

Paul

2016-06-11  Paul Thomas  <pa...@gcc.gnu.org>

    PR fortran/70673
    * frontend-passes.c (realloc_string_callback): Add a call to
    gfc_dep_compare_expr.

2016-06-11  Paul Thomas  <pa...@gcc.gnu.org>

    PR fortran/70673
    * gfortran.dg/pr70673.f90: New test.
Index: gcc/fortran/frontend-passes.c
===================================================================
*** gcc/fortran/frontend-passes.c       (revision 237168)
--- gcc/fortran/frontend-passes.c       (working copy)
*************** realloc_string_callback (gfc_code **c, i
*** 175,180 ****
--- 175,187 ----
    if (!gfc_check_dependency (expr1, expr2, true))
      return 0;

+   /* gfc_check_dependency doesn't always pick up identical expressions.
+      However, eliminating the above sends the compiler into an infinite
+      loop on valid expressions.  Without this check, the gimplifier emits
+      an ICE for a = a, where a is deferred character length.  */
+   if (!gfc_dep_compare_expr (expr1, expr2))
+     return 0;
+
    current_code = c;
    inserted_block = NULL;
    changed_statement = NULL;
Index: gcc/testsuite/gfortran.dg/pr70673.f90
===================================================================
*** gcc/testsuite/gfortran.dg/pr70673.f90       (revision 0)
--- gcc/testsuite/gfortran.dg/pr70673.f90       (working copy)
***************
*** 0 ****
--- 1,25 ----
+ ! { dg-do run }
+ !
+ ! Test the fix for PR70673
+ !
+ ! Contributed by David Kinniburgh  <davidgkinnibu...@yahoo.co.uk>
+ !
+ module m
+ contains
+   subroutine s(inp)
+     character(*), intent(in) :: inp
+     character(:), allocatable :: a
+     a = a           ! This used to ICE.
+     a = inp
+     a = a           ! This used to ICE too
+     if ((len (a) .ne. 5) .or. (a .ne. "hello")) call abort
+     a = a(2:3)      ! Make sure that temporary creation is not broken.
+     if ((len (a) .ne. 2) .or. (a .ne. "el")) call abort
+     deallocate (a)
+     a = a           ! This would ICE too.
+   end subroutine s
+ end module m
+
+   use m
+   call s("hello")
+ end

Reply via email to