[patch, fortran, RFC] warn about out-of-bounds errors in DO loops
Thomas Koenig
tkoenig@netcologne.de
Sun Sep 10 17:05:00 GMT 2017
Hello world,
the attached patch warns about certain cases where out-of-bound
array accesses can be detected at compile time.
This was inspired by an out-of-bound access in Polyhedron. A preliminary
version of this patch has already found one error in the testsuite.
The problem is what to warn for. Cases like
real, dimension(10) :: a
do i=1,11
if (somecondition) a(i) = 42.
end do
could be valid if somecondition is false for i=11.
What I did was to check if the subscript reference was
- warn for all cases with the new option -Wdo-subscript-extra,
included in -Wextra
- not warn if an expression is found in an if or select case
statement inside the do loop for -Wdo-subscript, included
in -Wall.
The patch also checks for slightly complicated expressions
like i*i - the only condition is that it should evaluate
to a constant if the loop variable is inserted.
Only constant bounds are checked.
See the test cases for some more details.
So, what do you think, especially about the choice of
options and warning levels?
Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p10.diff
Type: text/x-patch
Size: 11810 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170910/1e7a5655/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_subscript_1.f90
Type: text/x-fortran
Size: 1440 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170910/1e7a5655/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: do_subscript_2.f90
Type: text/x-fortran
Size: 1576 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170910/1e7a5655/attachment-0002.bin>
More information about the Gcc-patches
mailing list