Flag to warning about shape/alignment-change of explicit shape arrays arguments
Jonatan Öström
jonatan.ostrom@fysik.su.se
Thu Jun 6 12:11:00 GMT 2019
Sure, but then you have to bee lucky enough that your mistake makes the dummy too large.
I think the problem is that despite the whole machinery with the modules there is still no way to write safe and clear code.
With bb(:,:,:) as dummy it takes a lot to figure out what this array actually will look like, but for sure the shape that is passed will be represented correctly inside the routine. With bb(3,3,na), where na is passed, it is very clear what the array looks like, but the slightest index error silently makes the whole array nonsensical. If you could write bb(3,3,na) and know that unless the actual argument is exactly of shape (3,3,na) the compiler will complain, that would give very clear and safe code.
And of course an optional warning/error flag could realize that.
Best regards,
Jonatan
PS. Of course one can have the dummy bb(:,:,:) and check if(.not.all(shape(bb)==[3,3,na]))stop "...". I actually didn't consider this. But it is a bit ugly and boring to write and will be checked on runtime.
________________________________
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
Sent: Wednesday, June 5, 2019 12:40:43 AM
To: Jonatan Öström
Cc: fortran@gcc.gnu.org
Subject: Re: Flag to warning about shape/alignment-change of explicit shape arrays arguments
Yes, sequence association goes back to at least F77, sec. 15.9.3.3.
Within a program unit, the array declarator given for an array
provides all array declarator information needed for the array
in an execution of the program unit. The number and size of
dimensions in an actual argument array declarator may be different
from the number and size of the dimensions in an associated dummy
argument array declarator.
There is some additional verbiage about the size of the
dummy argument array cannot exceed the size of the actual
argument array.
% cat a.f90
program foo
integer a(10,10)
a = 1
call bar(a)
end program foo
subroutine bar(a)
integer a(3,50)
print *, a(1,1)
end subroutine bar
% gfortran8 -c a.f90
a.f90:4:12:
call bar(a)
1
Error: Actual argument contains too few elements for dummy
argument 'a' (100/150) at (1)
On Tue, Jun 04, 2019 at 10:00:05PM +0000, Jonatan Öström wrote:
> > Code contributions are always welcomed.
> Haha, the compiler is a very magic black box.
>
>
> I looked at the document. That sequence association is just the way it's always been, right? But with modern construct like modules and assumed shape, and comparing to numpy etc, this behavior seems unexpected. I wouldn't write a line without this flag if it was available.
>
>
> Anyway, thanks for your response!
>
>
> Best regards,
>
> Jonatan
>
>
> ________________________________
> From: Steve Kargl <sgk@troutmask.apl.washington.edu>
> Sent: Tuesday, June 4, 2019 23:05
> To: Jonatan Öström
> Cc: fortran@gcc.gnu.org
> Subject: Re: Flag to warning about shape/alignment-change of explicit shape arrays arguments
>
> Code contributions are always welcomed.
>
> IMHO, producing a warning for this specific use case
> where the F2018 standard specifically describes sequence
> association in 15.5.2.11 seems dubious to me.
>
> --
> steve
>
> On Tue, Jun 04, 2019 at 08:37:20PM +0000, Jonatan Öström wrote:
> > Well there are other such (optional) warnings. Truncated integer division for example, or unused variables. It would be reassuring to know that none of the arrays are changing shape, or to see that only the ones so intended do it, especially after doing changes that affect multiple arrays and/or routines.
> >
> >
> > Regards,
> >
> > Jonatan
> >
> > ________________________________
> > From: Steve Kargl <sgk@troutmask.apl.washington.edu>
> > Sent: Tuesday, June 4, 2019 8:21:27 PM
> > To: Jonatan Öström
> > Cc: fortran@gcc.gnu.org
> > Subject: Re: Flag to warning about shape/alignment-change of explicit shape arrays arguments
> >
> > On Tue, Jun 04, 2019 at 05:56:01PM +0000, Jonatan Öström wrote:
> > > Dear GCC developers, this is a feature request.
> > >
> > > It would be nice to have a flag like -Wrealign (or -Wreshape
> > > or some better name) to warn when an array 'aa' doesn't match
> > > the dimensions given in an explicit shape formal argument 'bb'.
> > >
> >
> > Seems odd to issue a warning for standard conforming code.
> >
> > --
> > Steve
>
> --
> Steve
> 20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
[http://img.youtube.com/vi/VWUpyCsUKR4/0.jpg]<https://www.youtube.com/watch?v=VWUpyCsUKR4>
Jake Kargl - Tempting Time - YouTube<https://www.youtube.com/watch?v=VWUpyCsUKR4>
www.youtube.com
Tempting Time. Written, performed, recorded, and mixed by Jake Kargl. Video by Andrew Swanson. ©2016 All rights reserved. Our YouTube channel for our covers:...
> 20161221 https://www.youtube.com/watch?v=IbCHE-hONow
[http://img.youtube.com/vi/IbCHE-hONow/0.jpg]<https://www.youtube.com/watch?v=IbCHE-hONow>
Foo Fighters - Learn To Fly Cover - YouTube<https://www.youtube.com/watch?v=IbCHE-hONow>
www.youtube.com
Our take on the Foo Fighters' hit "Learn to Fly" from their 1999 album, There Is Nothing Left to Lose.
--
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
[http://img.youtube.com/vi/VWUpyCsUKR4/0.jpg]<https://www.youtube.com/watch?v=VWUpyCsUKR4>
Jake Kargl - Tempting Time - YouTube<https://www.youtube.com/watch?v=VWUpyCsUKR4>
www.youtube.com
Tempting Time. Written, performed, recorded, and mixed by Jake Kargl. Video by Andrew Swanson. ©2016 All rights reserved. Our YouTube channel for our covers:...
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
[http://img.youtube.com/vi/IbCHE-hONow/0.jpg]<https://www.youtube.com/watch?v=IbCHE-hONow>
Foo Fighters - Learn To Fly Cover - YouTube<https://www.youtube.com/watch?v=IbCHE-hONow>
www.youtube.com
Our take on the Foo Fighters' hit "Learn to Fly" from their 1999 album, There Is Nothing Left to Lose.
More information about the Fortran
mailing list