From ae2c0367741852fdbc8b16d492e91a6cc14e44ab Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 27 Jun 2016 20:54:56 +0000 Subject: [PATCH] re PR fortran/70673 (ICE with module containing functions with allocatable character scalars) 2016-06-27 Paul Thomas PR fortran/70673 * frontend-passes.c (realloc_string_callback): Add a call to gfc_dep_compare_expr. 2016-06-27 Paul Thomas PR fortran/70673 * gfortran.dg/pr70673.f90: New test. From-SVN: r237804 --- gcc/fortran/frontend-passes.c | 7 +++++++ gcc/testsuite/gfortran.dg/pr70673.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr70673.f90 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index cc718e98c8b6..c8d7322dc3ce 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -156,6 +156,13 @@ realloc_string_callback (gfc_code **c, int *walk_subtrees, 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; diff --git a/gcc/testsuite/gfortran.dg/pr70673.f90 b/gcc/testsuite/gfortran.dg/pr70673.f90 new file mode 100644 index 000000000000..67856e0332e9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr70673.f90 @@ -0,0 +1,25 @@ +! { dg-do run } +! +! Test the fix for PR70673 +! +! Contributed by David Kinniburgh +! +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