From b757cef712bb1c8ab54495817d81730f92caa211 Mon Sep 17 00:00:00 2001 From: kargl Date: Tue, 30 Aug 2011 15:34:01 +0000 Subject: [PATCH] 2011-08-30 Steven G. Kargl PR fortran/45170 * trans-stmt.c (gfc_trans_allocate): Evaluate the substring. 2011-08-30 Steven G. Kargl PR fortran/45170 * gfortran.dg/allocate_with_source_2.f90: New test git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178329 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/trans-stmt.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ .../gfortran.dg/allocate_with_source_2.f90 | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/allocate_with_source_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d47e4115582..4f906b26666 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2011-08-30 Steven G. Kargl + + PR fortran/45170 + * trans-stmt.c (gfc_trans_allocate): Evaluate the substring. + 2011-08-29 Janus Weil PR fortran/50225 diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index a911a5b070e..7d8b4e00827 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -4783,6 +4783,10 @@ gfc_trans_allocate (gfc_code * code) || code->expr3->expr_type == EXPR_CONSTANT) { gfc_conv_expr (&se_sz, code->expr3); + gfc_add_block_to_block (&se.pre, &se_sz.pre); + se_sz.string_length + = gfc_evaluate_now (se_sz.string_length, &se.pre); + gfc_add_block_to_block (&se.pre, &se_sz.post); memsz = se_sz.string_length; } else if (code->expr3->mold diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ccaf17c06b4..0820eaf92fb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-08-30 Steven G. Kargl + + PR fortran/45170 + * gfortran.dg/allocate_with_source_2.f90: New test + 2011-08-30 Jason Merrill PR c++/50220 diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_2.f90 b/gcc/testsuite/gfortran.dg/allocate_with_source_2.f90 new file mode 100644 index 00000000000..8e48b226062 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_source_2.f90 @@ -0,0 +1,21 @@ +! { dg-do run } +! PR 45170 +! A variation of a theme for deferred type parameters. The +! substring reference in the source= portion of the allocate +! was not probably resolved. Testcase is a modified version +! of a program due to Hans-Werner Boschmann +! +program helloworld + character(:),allocatable::string + real::rnd + call hello(5, string) + if (string /= 'hello' .or. len(string) /= 5) call abort +contains + subroutine hello (n,string) + character(:),allocatable,intent(out)::string + integer,intent(in)::n + character(20)::helloworld="hello world" + allocate(string, source=helloworld(:n)) + end subroutine hello +end program helloworld -- 2.11.4.GIT