From bd7c4cff395030a6c60d7fdd0c9cf3a4a77040a0 Mon Sep 17 00:00:00 2001
From: pault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 4 Oct 2006 16:54:19 +0000
Subject: [PATCH] 2006-10-04  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29343
	* resolve.c (resolve_allocate_expr): Exclude derived types from
	search for dependences between allocated variables and the
	specification expressions for other allocations in the same
	statement.

2006-10-04  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29343
	* gfortran.dg/alloc_alloc_expr_2.f90: New test.




git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117435 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog                         |  8 ++++++++
 gcc/fortran/resolve.c                         |  7 ++++++-
 gcc/testsuite/ChangeLog                       |  5 +++++
 .../gfortran.dg/alloc_alloc_expr_2.f90        | 19 +++++++++++++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/alloc_alloc_expr_2.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 548a3d9cf981..5038694fcf13 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,11 @@
+2006-10-04  Paul Thomas <pault@gcc.gnu.org>
+
+	PR fortran/29343
+	* resolve.c (resolve_allocate_expr): Exclude derived types from
+	search for dependences between allocated variables and the
+	specification expressions for other allocations in the same
+	statement.
+
 2006-10-04  Paul Thomas  <pault@gcc.gnu.org>
 
 	PR fortran/29098
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index e28a93cbcdfe..b9653eb7eab7 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -3466,7 +3466,7 @@ resolve_allocate_expr (gfc_expr * e, gfc_code * code)
       pointer = e->symtree->n.sym->attr.pointer;
       dimension = e->symtree->n.sym->attr.dimension;
 
-      if (sym == e->symtree->n.sym)
+      if (sym == e->symtree->n.sym && sym->ts.type != BT_DERIVED)
 	{
 	  gfc_error ("The STAT variable '%s' in an ALLOCATE statement must "
 		     "not be allocated in the same statement at %L",
@@ -3571,6 +3571,11 @@ check_symbols:
       for (a = code->ext.alloc_list; a; a = a->next)
 	{
 	  sym = a->expr->symtree->n.sym;
+
+	  /* TODO - check derived type components.  */
+	  if (sym->ts.type == BT_DERIVED)
+	    continue;
+
 	  if ((ar->start[i] != NULL && find_sym_in_expr (sym, ar->start[i]))
 		 || (ar->end[i] != NULL && find_sym_in_expr (sym, ar->end[i])))
 	    {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 61168ffde1fe..5d9297e4f61e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-10-04  Paul Thomas  <pault@gcc.gnu.org>
+
+	PR fortran/29343
+	* gfortran.dg/alloc_alloc_expr_2.f90: New test.
+
 2006-10-04  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
 	* gfortran.dg/bounds_check_fail_1.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/alloc_alloc_expr_2.f90 b/gcc/testsuite/gfortran.dg/alloc_alloc_expr_2.f90
new file mode 100644
index 000000000000..16235e390465
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_alloc_expr_2.f90
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! This tests the fix for PR29343, in which the valid ALLOCATE statement
+! below triggered an error following the patch for PR20779 and PR20891.
+!
+! Contributed by Grigory Zagorodnev <grigory_zagorodnev@linux.intel.com>
+!
+        Subroutine ReadParameters (Album)
+        Implicit NONE
+
+
+        Type GalleryP
+                Integer       :: NoOfEntries
+                Character(80), Pointer :: FileName (:)
+        End Type GalleryP
+
+
+        Type(GalleryP), Intent(Out) :: Album
+        Allocate (Album%FileName   (Album%NoOfEntries))
+        end
-- 
GitLab