[Bug fortran/42008] New: Wrongly rejected derived types with default initializers in PURE procedures

View: New views
15 Messages — Rating Filter:   Alert me  

[Bug fortran/42008] New: Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Found at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/141265154c2fcc71

Reinhold Bader thinks that at least the second program, using default
initializers, is valid. Oddly, the program works with the TYPE is not defined
locally but use-associated.

The first program of M. Restelli is presumably wrong as it uses variables which
are implicitly declared as SAVE. - But one should re-check.


ifort v11.1, NAG f95 v5.1, pathscale 3.3b all accept all programs, g95 and
gfortran reject "one" and "two (B)".


!------ Program one ----------
module mod_xyz
 implicit none
contains
 pure subroutine psub()
  type ilist
    type(ilist), pointer :: next => null()
    integer :: i
  end type ilist
 end subroutine psub
end module mod_xyz
!------------------

!---------- Program two (A) ----------
module mod_xyz
 implicit none
 type ilist
   type(ilist), pointer :: next => null()
   integer :: i
 end type ilist
contains
 pure subroutine psub()
  type(ilist) :: var ! ACCEPTED
 end subroutine psub
end module mod_xyz

!---------- Program two (B) ----------
module mod_xyz2
 implicit none
contains
 pure subroutine psub()
  type ilist
    type(ilist), pointer :: next => null()
    integer :: i
  end type ilist
  type(ilist) :: var ! REJECTED
 end subroutine psub
end module mod_xyz2
!---------------------------------


--
           Summary: Wrongly rejected derived types with default initializers
                    in PURE procedures
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #1 from burnus at gcc dot gnu dot org  2009-11-11 12:54 -------
Misread the program one. I think it is also valid.

The constraint which is wrongly applied is:

"C1268 A local variable declared in the specification-part or
internal-subprogram-part of a pure subprogram shall not have the SAVE
attribute."

I could not find any (other) relevant constraint in "12.6 Pure procedures".


--

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |32834
              nThis|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #2 from burnus at gcc dot gnu dot org  2009-11-12 11:21 -------
*** Bug 42016 has been marked as a duplicate of this bug. ***


--

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrestelli at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



--

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jvdelisle at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-11-22 18:47:44
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2009-11-23 03:06 -------
This appears to fix this with no regressions.  I will commit as obvious
tomorrow.

Index: decl.c
===================================================================
--- decl.c      (revision 154430)
+++ decl.c      (working copy)
@@ -1865,13 +1865,6 @@ variable_decl (int elem)
              m = MATCH_ERROR;
            }

-         if (gfc_pure (NULL))
-           {
-             gfc_error ("Initialization of pointer at %C is not allowed in "
-                        "a PURE procedure");
-             m = MATCH_ERROR;
-           }
-
          if (m != MATCH_YES)
            goto cleanup;



--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #4 from burnus at gcc dot gnu dot org  2009-11-23 12:38 -------
Does your patch still reject

pure function test()
  integer, pointer :: p => null() ! INVALID per C1272
  integer :: test
  test = p
end function test

That is currently rejected as "Error: Initialization of pointer at (1) is not
allowed in a PURE procedure".

NAG f95 rejects it with:
  "ERROR: Local variable P of PURE procedure TEST has the SAVE attribute"
as "p" gets implicitly declared as SAVE. There might well be a check for it in
gfortran already, but seemingly no test case.

If there is no such test case, could you also add it?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2009-11-23 13:44 -------
Without the patch it is rejected, with the patch it is not.  I will look into
this further.


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #6 from burnus at gcc dot gnu dot org  2009-11-23 19:35 -------
(In reply to comment #5)
> Without the patch it is rejected, with the patch it is not.  I will look into
> this further.

Would something like  "if (...->attr.saved) { gfc_error }" work, combined with
the patch from comment 3?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #7 from jvdelisle at gcc dot gnu dot org  2009-11-24 04:32 -------
This seems to do the trick:

Index: decl.c
===================================================================
--- decl.c      (revision 154430)
+++ decl.c      (working copy)
@@ -1865,7 +1865,7 @@ variable_decl (int elem)
              m = MATCH_ERROR;
            }

-         if (gfc_pure (NULL))
+         if (gfc_pure (NULL) && gfc_state_stack->state != COMP_DERIVED)
            {
              gfc_error ("Initialization of pointer at %C is not allowed in "
                         "a PURE procedure");


None of the examples have any save attributes set, implied or otherwise.  This
patch allows the initial three examples and rejects the example in comment #4.
Is this what we are looking for?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #8 from burnus at gcc dot gnu dot org  2009-11-24 06:59 -------
(In reply to comment #7)
> +         if (gfc_pure (NULL) && gfc_state_stack->state != COMP_DERIVED)

Looks OK.

> None of the examples have any save attributes set, implied or otherwise.

Probably not in decl.c - but at some point, it should get that status as
  foo = init-expr
and
  fooptr => init-expr
implies SAVE. (Actually, the implied SAVE seems to works as expected - I just
checked for pointer.)


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #9 from jvdelisle at gcc dot gnu dot org  2009-11-25 02:41 -------
Subject: Bug 42008

Author: jvdelisle
Date: Wed Nov 25 02:41:20 2009
New Revision: 154530

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154530
Log:
2009-11-24  Jerry DeLisle  <jvdelisle@...>

        PR fortran/42008
        * gfortran.dg/pure_initializer_2.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pure_initializer_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #10 from jvdelisle at gcc dot gnu dot org  2009-11-25 02:42 -------
Subject: Bug 42008

Author: jvdelisle
Date: Wed Nov 25 02:42:22 2009
New Revision: 154531

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154531
Log:
2009-11-24  Jerry DeLisle  <jvdelisle@...>

        PR fortran/42008
        * decl.c (variable_decl): Do not error on initialization within a
        derived type specification of a pure procedure.

Modified:
    trunk/gcc/fortran/ChangeLog


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #11 from jvdelisle at gcc dot gnu dot org  2009-11-25 02:43 -------
I messed up the PR Number again.  The commit for above was:

Transmitting file data ..
Committed revision 154529.


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #12 from burnus at gcc dot gnu dot org  2009-11-25 13:21 -------
(In reply to comment #11)
> I messed up the PR Number again.  The commit for above was:

http://gcc.gnu.org/viewcvs?view=revision&revision=154529

2009-11-24  Jerry DeLisle  <jvdelisle@...>

        PR fortran/41807
        * decl.c (variable_decl): Do not error on initialization within a
        derived type specification of a pure procedure.

 * * *

Can this PR now be closed as fixed? Or do you want to backport it to 4.4?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008


[Bug fortran/42008] Wrongly rejected derived types with default initializers in PURE procedures

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #13 from jvdelisle at gcc dot gnu dot org  2009-11-26 03:26 -------
Fixed on mainline.


--

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42008