[Bug fortran/86322] ICE in reference_record with data statement

2019-01-10 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86322

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from kargl at gcc dot gnu.org ---
Actually close the PR!

[Bug fortran/86322] ICE in reference_record with data statement

2019-01-10 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86322

--- Comment #8 from kargl at gcc dot gnu.org ---
Fixed on trunk. Closing.

[Bug fortran/86322] ICE in reference_record with data statement

2019-01-10 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86322

--- Comment #7 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Thu Jan 10 18:45:38 2019
New Revision: 267820

URL: https://gcc.gnu.org/viewcvs?rev=267820=gcc=rev
Log:
2019-01-10  Steven G. Kargl  

PR fortran/86322
* decl.c (top_var_list): Set locus of expr.
(gfc_match_data): Detect pointer on non-rightmost part-refs.

2019-01-10  Steven G. Kargl  

PR fortran/86322
* gfortran.dg/pr86322_1.f90: New test.
* gfortran.dg/pr86322_2.f90: Ditto.
* gfortran.dg/pr86322_3.f90: Ditto.

Added:
trunk/gcc/testsuite/gfortran.dg/pr86322_1.f90
trunk/gcc/testsuite/gfortran.dg/pr86322_2.f90
trunk/gcc/testsuite/gfortran.dg/pr86322_3.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/decl.c
trunk/gcc/testsuite/ChangeLog

[Bug fortran/86322] ICE in reference_record with data statement

2019-01-09 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86322

kargl at gcc dot gnu.org changed:

   What|Removed |Added

  Known to work|8.1.0   |
   Assignee|unassigned at gcc dot gnu.org  |kargl at gcc dot gnu.org

--- Comment #6 from kargl at gcc dot gnu.org ---
Remove 'Known to work" as this has never worked.

[Bug fortran/86322] ICE in reference_record with data statement

2019-01-08 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86322

--- Comment #5 from Steve Kargl  ---
On Tue, Jan 08, 2019 at 09:40:29PM +, sgk at troutmask dot
apl.washington.edu wrote:
> 
> Naw, it is is not due to my patch.  Rather my patch has
> exposed or uncovered a bug in gfortran.  gfortran needs
> to check
> 
> F2018:C877 (R839) A data-i-do-object or a variable that appears as a
>data-stmt-object shall not be an object designator in which a pointer
>appears other than as the entire rightmost part-ref .
> 
> In decl.c (gfc_match_data), gfortran needs a check for C877.
> I haven't gotten around to fixing this yet, and I likely won't
> for the foreseeable future.
> 

Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c  (revision 267735)
+++ gcc/fortran/decl.c  (working copy)
@@ -655,6 +655,15 @@ gfc_match_data (void)
 "near %C in DATA statement");
  goto cleanup;
}
+
+ if (e->symtree->n.sym->ts.type == BT_DERIVED
+ && e->symtree->n.sym->attr.pointer
+ && e->ref->type == REF_COMPONENT)
+   {
+ gfc_error ("part-ref with pointer attribute near %L is not "
+"rightmost component of data-stmt-object", >where);
+ goto cleanup;
+   }
}

   m = top_val_list (new_data);

The above is marginally correct.  It may be a starting point for
someone who cares about this bug and wants to fix it.  The patch
checks if the leftmost part-ref has the pointer attribute and 
the variable is a REF_COMPONENT, which means that a part-ref
other than the rightmost component has the pointer attribute.
This is the simple case.  A better patch would need to check
each part-ref for the pointer attribute.  That is none of a, b,
c, d, or e in a%b%c%d%e%i can have a pointer attribute.

Note, this works

program bar
   type a
 integer, pointer :: i
   end type a
   type b
 type(a) j
   end type b
   integer, target, save :: k = 42
   type(b) x
   data x%j%i/k/
   print *, x%j%i
end program bar

This gives an ICE like the one reported in this PR.  'j'
has the pointer attribute and so the program should be
rejected.

program bah
   type a
 integer :: i
   end type a
   type b
 type(a), pointer :: j
   end type b
   integer, target, save :: k = 42
   type(b) x
   data x%j%i /k/
   print *, x%j%i
end program bah