re PR fortran/45170 ([F2003] allocatable character lengths)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 30 Aug 2011 15:34:01 +0000 (15:34 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Tue, 30 Aug 2011 15:34:01 +0000 (15:34 +0000)
2011-08-30  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/45170
* trans-stmt.c (gfc_trans_allocate): Evaluate the substring.

2011-08-30  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/45170
* gfortran.dg/allocate_with_source_2.f90: New test

From-SVN: r178329

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

index d47e4115582f2885cebdb066d7c03ea367b6af17..4f906b26666bc1cfadb93c4b1a651a29c70ae1db 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/45170
+       * trans-stmt.c (gfc_trans_allocate): Evaluate the substring.
+
 2011-08-29  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/50225
index a911a5b070e07f02c3d10988ac93096903e03012..7d8b4e00827f600fa2901652c5669503b4be2967 100644 (file)
@@ -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
index ccaf17c06b4e22c073ab183e487474f1bbd13a5c..0820eaf92fbd6c1ada3b9e84262f654075e375c5 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/45170
+       * gfortran.dg/allocate_with_source_2.f90: New test
+
 2011-08-30  Jason Merrill  <jason@redhat.com>
 
        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 (file)
index 0000000..8e48b22
--- /dev/null
@@ -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 <boschmann at tp1
+! dot physik dot uni-siegen dot de>
+!
+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