Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

array operations on non-conforming arrays -- do compilers catch them?

36 views
Skip to first unread message

Beliavsky

unread,
Mar 30, 2007, 4:56:08 PM3/30/07
to
I am finding that most Fortran 95 compilers do not catch, even at run
time, many invalid uses of non-conforming arrays when array subscripts
are variables. For the following invalid code,

program xsum_nonconform
integer, parameter :: n = 3
integer :: i,ivec(n)
ivec = 1
do i=n,n
print*,ivec(1:n-1) + ivec(1:i)
end do
end program xsum_nonconform

G95, Intel Visual Fortran, and Salford don't detect a problem at
compile or run time, but gfortran -fbounds-check says

Fortran runtime error: Array bound mismatch, size mismatch for
dimension 1 of array 'ivec' (in file 'xsum_nonconform.f90', at line 6)

and Lahey/Fujitsu with -chk says something similar.

I discovered such a bug in my production code using the new Gfortran
windows binary, dated 2007-03-29 .

Bart Vandewoestyne

unread,
Mar 30, 2007, 5:13:20 PM3/30/07
to

NAGWare Fortran 95 compiler Release 5.1(282) on Intel Linux and with
the -C=all option gives the following error at runtime:

Rank 1 of IVEC(1:I) has extent 3 instead of 2
Program terminated by fatal error
Aborted

Kind regards,
Bart

--
"Share what you know. Learn what you don't."

Lane Straatman

unread,
Mar 30, 2007, 8:23:25 PM3/30/07
to

"Beliavsky" <beli...@aol.com> wrote in message
news:1175288168....@y80g2000hsf.googlegroups.com...

>I am finding that most Fortran 95 compilers do not catch, even at run
> time, many invalid uses of non-conforming arrays when array subscripts
> are variables. For the following invalid code,
>
> program xsum_nonconform
> integer, parameter :: n = 3
> integer :: i,ivec(n)
> ivec = 1
> do i=n,n
> print*,ivec(1:n-1) + ivec(1:i)
> end do
> end program xsum_nonconform
Is it your intent to have the do loop go from n to n?
--
LS

Beliavsky

unread,
Mar 31, 2007, 9:05:53 AM3/31/07
to
On Mar 30, 7:23 pm, "Lane Straatman" <inva...@invalid.net> wrote:
> "Beliavsky" <beliav...@aol.com> wrote in message

>
> news:1175288168....@y80g2000hsf.googlegroups.com...>I am finding that most Fortran 95 compilers do not catch, even at run
> > time, many invalid uses of non-conforming arrays when array subscripts
> > are variables. For the following invalid code,
>
> > program xsum_nonconform
> > integer, parameter :: n = 3
> > integer :: i,ivec(n)
> > ivec = 1
> > do i=n,n
> > print*,ivec(1:n-1) + ivec(1:i)
> > end do
> > end program xsum_nonconform
>
> Is it your intent to have the do loop go from n to n?

Yes. For the simpler but equivalent program

program xsum_nonconform_simple


integer, parameter :: n = 3
integer :: i,ivec(n)
ivec = 1

i = n


print*,ivec(1:n-1) + ivec(1:i)

end program xsum_nonconform_simple

the compilers behave the same way, but simplifying further by plugging
in n for i in the print statement to give

program xxnonconform


integer, parameter :: n = 3

integer :: ivec(n)
ivec = 1
print*,ivec(1:n-1) + ivec(1:n)
end program xxnonconform

gives a compile-time error for gfortran and g95 (the only two I
tried), with gfortran saying

xxnonconform.f90:5.7-25:

print*,ivec(1:n-1) + ivec(1:n)
1 2
Error: Shapes for operands at (1) and (2) are not conformable

John Harper

unread,
Apr 1, 2007, 6:32:11 PM4/1/07
to
In article <1175288168....@y80g2000hsf.googlegroups.com>,

Beliavsky <beli...@aol.com> wrote:
>I am finding that most Fortran 95 compilers do not catch, even at run
>time, many invalid uses of non-conforming arrays when array subscripts
>are variables. For the following invalid code,
>
>program xsum_nonconform
>integer, parameter :: n = 3
>integer :: i,ivec(n)
>ivec = 1
>do i=n,n
> print*,ivec(1:n-1) + ivec(1:i)
>end do
>end program xsum_nonconform
>
>G95, Intel Visual Fortran, and Salford don't detect a problem at
>compile or run time, but gfortran -fbounds-check [does at run time]
...

>and Lahey/Fujitsu with -chk says something similar.

NAG f95 -C=all also finds that error at run time.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045

0 new messages