[gfortran,patch] Fix multiple evaluation of index with bounds checking

FX Coudert fxcoudert@gmail.com
Thu Jul 12 10:49:00 GMT 2007


The attached patch is a simple one-liner that avoids multiple  
evaluation of array index when performing bounds checking in some  
conditions (PR 32036). It does so by creating a SAVE_EXPR (an expr  
whose content is only evaluated once) [1]. Simple, and easy to  
review! (I also committed it as obvious, but since I've not been  
working too much on gfortran lately, I decided it's best to ask for  
review.)

Bootstrapped and regtested on x86_64-linux (both with and without - 
fbounds-check), comes with one testcase. I also had to modify  
gfortran.dg/do_iterator_2.f90 because in its current form, it's not  
legal code (we evaluate line(0:0) where line is a character variable;  
this is flagged by running the testsuite with -fbounds-check).

OK for mainline?

Thanks,
FX

[1] The usual trick for forcing single evaluation in gfortran is to  
use gfc_evaluate_now. In that case, using it would have required  
creating a new block of code to contain all the evaluations, then add  
it before the block of bounds checking, which is more trouble than  
using SAVE_EXPR and letting the middle-end perform the work for us.




:ADDPATCH fortran:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr32036.ChangeLog
Type: application/octet-stream
Size: 332 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070712/36fddc00/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr32036.diff
Type: application/octet-stream
Size: 2361 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070712/36fddc00/attachment-0001.obj>


More information about the Gcc-patches mailing list