diff options
author | Fritz Reese <Reese-Fritz@zai.com> | 2014-08-31 22:28:30 +0000 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2014-09-01 00:28:30 +0200 |
commit | 03e46144faa1444571fcd6192691cb3675be1f6e (patch) | |
tree | e2f3e3385b83e291ae5c3939713fe5ddda1c3979 /gcc | |
parent | cbb4d6a4b99445fe2f29f17c9a83602d3b9f1606 (diff) | |
download | gcc-03e46144faa1444571fcd6192691cb3675be1f6e.zip gcc-03e46144faa1444571fcd6192691cb3675be1f6e.tar.gz gcc-03e46144faa1444571fcd6192691cb3675be1f6e.tar.bz2 |
re PR fortran/62309 (-fno-automatic with -finit-local prevents initialization of automatics in recursive functions)
2014-08-31 Fritz Reese <Reese-Fritz@zai.com>
PR fortran/62309
* resolve.c (apply_default_init_local): Don't treat variables
in RECURSIVE procedures as saved.
2014-08-31 Fritz Reese <Reese-Fritz@zai.com>
Tobias Burnus <burnus@net-b.de>
PR fortran/62309
* gcc/testsuite/gfortran.dg/auto_save_2.f90: New.
Co-Authored-By: Tobias Burnus <burnus@net-b.de>
From-SVN: r214771
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/resolve.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/auto_save_2.f90 | 84 |
4 files changed, 97 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 57b76bf..eab86ed 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2014-08-31 Fritz Reese <Reese-Fritz@zai.com> + + PR fortran/62309 + * resolve.c (apply_default_init_local): Don't treat variables + in RECURSIVE procedures as saved. + 2014-08-31 Tobias Burnus <burnus@net-b.de> * trans-decl.c (gfc_build_builtin_function_decls): Add diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 52aae90e..da732db 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -10780,6 +10780,7 @@ apply_default_init_local (gfc_symbol *sym) result variable, which are also nonstatic. */ if (sym->attr.save || sym->ns->save_all || (gfc_option.flag_max_stack_var_size == 0 && !sym->attr.result + && !sym->ns->proc_name->attr.recursive && (!sym->attr.dimension || !is_non_constant_shape_array (sym)))) { /* Don't clobber an existing initializer! */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8cc10e7..953eafd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-08-31 Fritz Reese <Reese-Fritz@zai.com> + Tobias Burnus <burnus@net-b.de> + + PR fortran/62309 + * gcc/testsuite/gfortran.dg/auto_save_2.f90: New. + 2014-08-31 Tobias Burnus <burnus@net-b.de> * gfortran.dg/coarray_lib_comm_1.f90: New. diff --git a/gcc/testsuite/gfortran.dg/auto_save_2.f90 b/gcc/testsuite/gfortran.dg/auto_save_2.f90 new file mode 100644 index 0000000..07d5d0c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/auto_save_2.f90 @@ -0,0 +1,84 @@ +! { dg-do run } +! { dg-options "-fno-automatic -finit-local-zero -fdump-tree-original" } +! +! PR fortran/62309 +! +! Make sure variables are saved with -fno-automatic except in +! functions marked RECURSIVE, and that they are still initialized with +! -finit-local-zero. +! + +function f (x) +implicit none + integer f, x + integer a ! should be SAVEd + a = a + x ! should increment by y every time + f = a + return +endfunction + +function f2 (x) +implicit none + integer f2, x + block + named: block + block + integer a ! should be SAVEd + a = a + x ! should increment by y every time + f2 = a + end block + end block named + end block + return +endfunction + +recursive function g (x) +implicit none + integer g, x + integer b ! should be automatic + b = b + x ! should be set to y every time + g = b + return +endfunction + +recursive function g2 (x) +implicit none + integer g2, x + block + named: block + block + integer b ! should be automatic + b = b + x ! should be set to y every time + g2 = b + end block + end block named + end block + return +endfunction + +implicit none +integer f, f2, g, g2 + +! Should return static value of a; accumulates y +if ( f(3) .ne. 3 ) call abort () +if ( f(4) .ne. 7 ) call abort () +if ( f(2) .ne. 9 ) call abort () + +if ( f2(3) .ne. 3 ) call abort () +if ( f2(4) .ne. 7 ) call abort () +if ( f2(2) .ne. 9 ) call abort () + +! Should return automatic value of a; equal to y each time +if ( g(3) .ne. 3 ) call abort () +if ( g(4) .ne. 4 ) call abort () +if ( g(2) .ne. 2 ) call abort () + +if ( g2(3) .ne. 3 ) call abort () +if ( g2(4) .ne. 4 ) call abort () +if ( g2(2) .ne. 2 ) call abort () + +end + +! { dg-final { scan-tree-dump-times " static integer\\\(kind=4\\\) a = 0;" 2 "original" } } +! { dg-final { scan-tree-dump-times " b = 0;" 2 "original" } } +! { dg-final { cleanup-tree-dump "original" } } |