[patch, fortran] Compile-time check for change in DO variable in contained procedures
Thomas Koenig
tkoenig@netcologne.de
Tue Aug 4 19:01:58 GMT 2020
Hello world,
the attached patch issues an error for something that I am sure most
people did at least once (I know I did), something like
do i=1,10
call foo
end do
...
contains
subroutine foo
do i=1,5
...
end do
which is, of course, illegal, but the programmer's fault. We issue an
error with -fcheck=all, but a compile-time is better, of course.
As you can see from the modification of do_check_4.f90, you have to go
to some lengths to fool the compiler with this patch.
As an aside, I could really have used three places for the error
message here. As is, I settled for the place of the call from
the DO loop checked, and the place where it is modified. With
the name of the variable, the user should be able to figure out
what's wrong.
Regression-tested. OK for trunk?
Best regards
Thomas
Static analysis for definition of DO index variables in contained
procedures.
When encountering a procedure call in a DO loop, this patch checks if
the call is to a contained procedure, and if it is, check for
changes in the index variable.
gcc/fortran/ChangeLog:
PR fortran/96469
* frontend-passes.c (doloop_contained_function_call): New
function.
(doloop_contained_procedure_code): New function.
(CHECK_INQ): Macro for inquire checks.
(doloop_code): Invoke doloop_contained_procedure_code and
doloop_contained_function_call if appropriate.
(do_intent): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/96469
* gfortran.dg/do_check_4.f90: Hide change in index variable
from compile-time analysis.
* gfortran.dg/do_check_4.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p2.diff
Type: text/x-patch
Size: 9123 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200804/1f90b480/attachment-0001.bin>
More information about the Gcc-patches
mailing list