[Patch, Fortran, F08] PR 55207: Variables declared in the main program should implicitly get the SAVE attribute
Janus Weil
janus@gcc.gnu.org
Fri Mar 14 19:30:00 GMT 2014
Hi all,
attached is a patch which implicitly sets the SAVE attribute for all
variables in the main program, as demanded by the Fortran 2008
standard. This fixes an ICE with pointer initialization (see
pointer_init_9.f90). Also a few exisiting test cases had to be changed
to accomodate for the modified behavior.
Regtests cleanly on x86_64-unknown-linux-gnu. Ok for trunk or wait for
next stage1?
Cheers,
Janus
2014-03-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/55207
* decl.c (match_attr_spec): Variables in the main program implicitly
get the SAVE attribute in Fortran 2008.
2014-03-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/55207
* gfortran.dg/assumed_rank_7.f90: Explicitly deallocate variables.
* gfortran.dg/c_ptr_tests_16.f90: Put into subroutine.
* gfortran.dg/inline_sum_bounds_check_1.f90: Add
-Wno-aggressive-loop-optimizations and remove an unused variable.
* gfortran.dg/intent_optimize_1.f90: Put into subroutine.
* gfortran.dg/pointer_init_9.f90: New.
* gfortran.dg/volatile4.f90: Put into subroutine.
* gfortran.dg/volatile6.f90: New.
-------------- next part --------------
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 208566)
+++ gcc/fortran/decl.c (working copy)
@@ -3827,9 +3827,11 @@ match_attr_spec (void)
}
}
- /* Since Fortran 2008 module variables implicitly have the SAVE attribute. */
- if (gfc_current_state () == COMP_MODULE && !current_attr.save
- && (gfc_option.allow_std & GFC_STD_F2008) != 0)
+ /* Since Fortran 2008, variables declared in a MODULE or PROGRAM
+ implicitly have the SAVE attribute. */
+ if ((gfc_current_state () == COMP_MODULE
+ || gfc_current_state () == COMP_PROGRAM)
+ && !current_attr.save && (gfc_option.allow_std & GFC_STD_F2008) != 0)
current_attr.save = SAVE_IMPLICIT;
colon_seen = 1;
Index: gcc/testsuite/gfortran.dg/assumed_rank_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/assumed_rank_7.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/assumed_rank_7.f90 (working copy)
@@ -24,6 +24,8 @@ call bar(ac)
call bar(at)
if (i /= 12) call abort()
+deallocate(ac,at)
+
contains
subroutine bar(x)
type(t) :: x(..)
Index: gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90
===================================================================
--- gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/c_ptr_tests_16.f90 (working copy)
@@ -3,7 +3,7 @@
!
! PR fortran/46974
-program test
+subroutine test
use ISO_C_BINDING
implicit none
type(c_ptr) :: m
@@ -15,7 +15,7 @@
.and. int(z'41424345') /= a &
.and. int(z'4142434500000000',kind=8) /= a) &
call i_do_not_exist()
-end program test
+end subroutine
! Examples contributed by Steve Kargl and James Van Buskirk
Index: gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90 (working copy)
@@ -1,9 +1,9 @@
! { dg-do run }
-! { dg-options "-fbounds-check" }
+! { dg-options "-fbounds-check -Wno-aggressive-loop-optimizations" }
integer, parameter :: nx = 3, ny = 4
- integer :: i, j, too_big
+ integer :: i, too_big
integer, parameter, dimension(nx,ny) :: p = &
reshape((/ (i*i, i=1,size(p)) /), shape(p))
Index: gcc/testsuite/gfortran.dg/intent_optimize_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/intent_optimize_1.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/intent_optimize_1.f90 (working copy)
@@ -6,7 +6,10 @@
! honoured.
!
! PR fortran/43665
-!
+
+
+subroutine test
+
interface
subroutine foo(x)
integer, intent(in) :: x
Index: gcc/testsuite/gfortran.dg/volatile4.f90
===================================================================
--- gcc/testsuite/gfortran.dg/volatile4.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/volatile4.f90 (working copy)
@@ -2,6 +2,8 @@
! { dg-options "-O2 -fdump-tree-optimized" }
! Tests whether volatile really works
! PR fortran/29601
+
+subroutine sub
logical, volatile :: t1
logical :: t2
integer :: i
Index: gcc/testsuite/gfortran.dg/volatile6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/volatile6.f90 (revision 208566)
+++ gcc/testsuite/gfortran.dg/volatile6.f90 (working copy)
@@ -2,6 +2,8 @@
! { dg-options "-O2 -fdump-tree-optimized" }
! Tests whether volatile really works for arrays
! PR fortran/29601
+
+subroutine sub
logical, allocatable, volatile :: t1(:)
logical, allocatable :: t2(:)
integer :: i
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pointer_init_9.f90
Type: text/x-fortran
Size: 297 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20140314/709cf7f5/attachment.bin>
More information about the Fortran
mailing list