public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/85798 -- Check for allocatable components in data statement
@ 2018-12-16 19:04 Steve Kargl
  2018-12-21  1:04 ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2018-12-16 19:04 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 519 bytes --]

The attached patch has been tested on i586-*-freebsd and x86_64-*-freebsd.
If a data-statement-object is a component of a derived type, it checks if
that component is allocatable.

2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>

	PR fortran/85798
	* decl.c (gfc_match_data): If a component of a derived type entity
	appears in data statement, check that does not have the allocatable
	attribute.
 
2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>

	PR fortran/85798
	* gfortran.dg/pr85798.f90: New test.

-- 
Steve

[-- Attachment #2: pr85798.diff --]
[-- Type: text/x-diff, Size: 1792 bytes --]

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 267189)
+++ gcc/fortran/decl.c	(working copy)
@@ -596,6 +596,7 @@ match
 gfc_match_data (void)
 {
   gfc_data *new_data;
+  gfc_expr *e;
   match m;
 
   /* Before parsing the rest of a DATA statement, check F2008:c1206.  */
@@ -630,6 +631,30 @@ gfc_match_data (void)
 	  gfc_error ("Invalid substring in data-implied-do at %L in DATA "
 		     "statement", &new_data->var->list->expr->where);
 	  goto cleanup;
+	}
+
+      /* Check for an entity with an allocatable component, which is not
+	 allowed.  */
+      e = new_data->var->expr;
+      if (e)
+	{
+	  bool invalid;
+
+	  invalid = false;
+	  for (gfc_ref *ref = e->ref; ref; ref = ref->next)
+	    if ((ref->type == REF_COMPONENT
+		 && ref->u.c.component->attr.allocatable)
+		|| (ref->type == REF_ARRAY
+		    && e->symtree->n.sym->attr.pointer != 1
+		    && ref->u.ar.as && ref->u.ar.as->type == AS_DEFERRED))
+	      invalid = true;
+
+	  if (invalid)
+	    {
+	      gfc_error ("Allocatable component or deferred-shaped array "
+			 "near %C in DATA statement");
+	      goto cleanup;
+	    }
 	}
 
       m = top_val_list (new_data);
Index: gcc/testsuite/gfortran.dg/pr85798.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85798.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr85798.f90	(working copy)
@@ -0,0 +1,14 @@
+! { dg-do compile }
+program p
+   type t
+      integer, allocatable :: a(:)
+   end type
+   type u
+      real x
+      type(t) y
+   end type
+   type(t) :: z
+   type(u) :: q
+   data z%a(1) / 789 /     ! { dg-error "Allocatable component" }
+   data q%y%a(1) / 789 /   ! { dg-error "Allocatable component" }
+end

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/85798 -- Check for allocatable components in data statement
  2018-12-16 19:04 [PATCH] PR fortran/85798 -- Check for allocatable components in data statement Steve Kargl
@ 2018-12-21  1:04 ` Steve Kargl
  2018-12-22 20:08   ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2018-12-21  1:04 UTC (permalink / raw)
  To: fortran, gcc-patches

On Sun, Dec 16, 2018 at 11:04:44AM -0800, Steve Kargl wrote:
> The attached patch has been tested on i586-*-freebsd and x86_64-*-freebsd.
> If a data-statement-object is a component of a derived type, it checks if
> that component is allocatable.
> 
> 2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/85798
> 	* decl.c (gfc_match_data): If a component of a derived type entity
> 	appears in data statement, check that does not have the allocatable
> 	attribute.
>  
> 2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/85798
> 	* gfortran.dg/pr85798.f90: New test.
> 

Ping.

-- 
Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/85798 -- Check for allocatable components in data statement
  2018-12-21  1:04 ` Steve Kargl
@ 2018-12-22 20:08   ` Steve Kargl
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Kargl @ 2018-12-22 20:08 UTC (permalink / raw)
  To: fortran, gcc-patches

On Thu, Dec 20, 2018 at 05:00:19PM -0800, Steve Kargl wrote:
> On Sun, Dec 16, 2018 at 11:04:44AM -0800, Steve Kargl wrote:
> > The attached patch has been tested on i586-*-freebsd and x86_64-*-freebsd.
> > If a data-statement-object is a component of a derived type, it checks if
> > that component is allocatable.
> > 
> > 2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>
> > 
> > 	PR fortran/85798
> > 	* decl.c (gfc_match_data): If a component of a derived type entity
> > 	appears in data statement, check that does not have the allocatable
> > 	attribute.
> >  
> > 2018-12-16  Steven G . Kargl  <kargl@gcc.gnu.org>
> > 
> > 	PR fortran/85798
> > 	* gfortran.dg/pr85798.f90: New test.
> > 
> 
> Ping.
> 

Committed.

-- 
Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-22 19:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-16 19:04 [PATCH] PR fortran/85798 -- Check for allocatable components in data statement Steve Kargl
2018-12-21  1:04 ` Steve Kargl
2018-12-22 20:08   ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).