ig25@linux-fd1f:~/Krempel/Block> cat block.f90 program main integer :: n n = 3 block block block real, dimension(n) :: a end block end block end block end program main ig25@linux-fd1f:~/Krempel/Block> gfortran block.f90 block.f90:7:24: real, dimension(n) :: a 1 Error: Variable »n« cannot appear in the expression at (1) This is bogus. Any solution should include the case of an arbitrary number of nested blocks.
Is not the code invalid?
(In reply to Dominique d'Humieres from comment #1) > Is not the code invalid? I don't think it is invalid. This works as expected: program main integer :: n n = 3 block block real, dimension(n) :: a end block end block end program main
Some people write strange code. ;-) This is related to the inline matmul patch isn't it?
The reason is that I want to make creation of temporary variables for arrays more sane. Currently, temporary arrays are handled using an allocatable array variable. This obviously does not work if -fno-realloc-lhs is specified, and introduces unneeded complexity in the generated code, which is hard for the middle-end optimizers to remove. What I want to do is, if I want to create a temporary variable for an array, is to change real, dimension(something,other) :: a a(f(x),1:3) into block freeze = f(x) size_1 = 1; size_2 = 3; block real, dimension(size_1, size_2) :: a_tmp a_tmp(:,;) = a(freeze, 1:3) ... end block end block While this might work in the most simple cases, I don't want to introduce instability by hitting a bug with too many nesting levels.
Author: tkoenig Date: Sat May 16 12:33:01 2015 New Revision: 223238 URL: https://gcc.gnu.org/viewcvs?rev=223238&root=gcc&view=rev Log: 2015-05-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66113 * expr.c (is_parent_of_current_ns): New function. (check_restricted): Use it. 2015-05-16 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66113 * gfortran.dg/block_14.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/block_14.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk, closing.