gfortran and -fbounds-check
mimo
mimo2@free.fr
Mon Mar 19 17:46:00 GMT 2007
Tobias Schlüter a écrit :
> mimo wrote:
>> Hi all,
>> Is there some way to force gfortran not to evaluate the second
>> operand of a .AND. or .OR. when the result is determined by the first
>> argument ?
>> I try to use -fbounds-check on a program which have some instructions
>> of the type :
>> REAL A(100)
>> DO I=1,1000
>> IF( I <= 100 .AND. A(I) > 0. ) do something
>> ENDDO
>> and this would give me an "Array reference out of bounds" when I=101
>
> Hi mimo,
>
> can you file a bug in our bug tracking system. We actually do
> short-circuit the logical expression. Unfortunately, the
> bounds-checking happens before the evaluation of the logical expression,
> i.e. the generated code looks like this (taken from the
> -fdump-tree-original output):
> if ((logical4) __builtin_expect (i <= 0, 0))
> {
> _gfortran_runtime_error ("Array reference out of
> bounds...");
> }
> if ((logical4) __builtin_expect (i > 100, 0))
> {
> _gfortran_runtime_error ("Array reference out of
> bounds...");
> }
> if (i <= 100 && a[NON_LVALUE_EXPR <i> + -1] > 0.0)
> {
> In other words, the illegal access would never happen, but
> we throw the error nonetheless.
>
> - Tobi
Thanks tobi for this quick answer. I will file the bug.
mimo
More information about the Fortran
mailing list