Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29267 Discussions

Array constructor changes array bounds with /assume:realloc_lhs.

Ben3
Beginner
694 Views
Hi,
When I use an array constructors for an allocatable array with /assume:realloc_lhs, it changes the bounds of the allocatable array to 1 to size(array):
[fortran]program test
  implicit none
  integer, dimension(:), allocatable :: x
  integer :: i
  allocate(x(-1:22))
  write(*, *) lbound(x), ubound(x)
  x = [ (modulo(i-1, 20) + 1, i = -1, 22) ]
  write(*, *) lbound(x), ubound(x)
end program test[/fortran]

This produces
[plain]L:\>test
          -1          22
           1          24
[/plain]

Is this a bug, or intended behaviour for /assume:realloc_lhs. I can stop the automatic reallocation by using x(:) in the assignment.

Version:
[plain]L:\>ifort
Intel Visual Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.4.196 Build 20110427
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.[/plain]

Cheers,
Ben

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
694 Views
in the statement x=[(modulo(i-1,20)+1,i=-1,22)]

The rhs is a 1-based array with 24 elements (equivilent to data(1:24))

If you declare y(:) and use

y = x ! (x(-1:22)

The rhs is array of (-1:22) and the lhs receives descriptor as well, resulting in y(-1:22)

However, if you have

y = (x)

The the rhs is the data contained in x(-1:22) without regard to the indexing (iow equivilent1-based data(1:24)

Same issue if you use

y = x(-1:22)

rhs is 1-based reference to data represented by x(-1:22)

The compiler is not broken as far as I know.

Jim Dempsey
0 Kudos
jimdempseyatthecove
Honored Contributor III
694 Views
If you wish to preserve the indicies check out FOR_DESCRIPTOR_ASSIGN

Jim Dempsey
0 Kudos
Steven_L_Intel1
Employee
694 Views
Actually, this is a bug. The standard requires reallocation only when the shape of the array changes, and shape is rank and extent (number of elements). The compiler should not be doing the reallocation and bounds change as long as the number of elements match. This will be fixed in Update 6, scheduled for September.
0 Kudos
Ben3
Beginner
694 Views
Thanks, Steve and Jim.

In the meantime, I'll just use x(:) when I don't want reallocation.

Ben
0 Kudos
Reply