Bug 66113 - Variable n cannot appear in the expression with nested blocks
Summary: Variable n cannot appear in the expression with nested blocks
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 48997
  Show dependency treegraph
 
Reported: 2015-05-11 19:28 UTC by Thomas Koenig
Modified: 2015-05-16 12:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2015-05-11 19:28:27 UTC
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.
Comment 1 Dominique d'Humieres 2015-05-11 20:01:02 UTC
Is not the code invalid?
Comment 2 Thomas Koenig 2015-05-11 20:34:29 UTC
(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
Comment 3 Mikael Morin 2015-05-11 20:56:54 UTC
Some people write strange code. ;-)
This is related to the inline matmul patch isn't it?
Comment 4 Thomas Koenig 2015-05-12 06:52:16 UTC
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.
Comment 5 Thomas Koenig 2015-05-16 12:33:33 UTC
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
Comment 6 Thomas Koenig 2015-05-16 12:35:30 UTC
Fixed on trunk, closing.