public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* gfortran 10.2 and tests in debug mode
@ 2021-02-06 16:59 Patrick Begou
  2021-02-06 17:18 ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Begou @ 2021-02-06 16:59 UTC (permalink / raw)
  To: fortran

Hi,

this is my first post on this list.

I have a strange behavior with gfortran 10.2 freshly deployed.  This
small test-case program below give a segfault in debug mode only with
gfortran 10.2 and not with 7.3, 6.3.0 or 4.8.5.

In the real life, the do_it could be a parameter received in a function
saying "if 0 do nothing else do something every do_it timestep".

In my mind, if the first condition in the if line is false, the second
one must not be evaluated. But with gfortran 10.2 it is.

    program badtest
       implicit none
       integer:: i,do_it=0

       do i=1,4
          if (do_it > 0 .and. mod(i,do_it) .eq.0) then
             print*, "Do it!"
          else
             print*, "No!"
          endif
       enddo
    end program badtest


Compilation with:

*gfortran -O0 -Wall -g  -ffree-line-length-none -fbacktrace
-ffpe-trap=zero,overflow -finit-real=nan -fcheck=all badtest.F90 -o badtest*

I've split all such tests in 2 consecutives "if" lines in my code to
allow debuging but not sure it is the right behavior in Fortran.

Patrick


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gfortran 10.2 and tests in debug mode
  2021-02-06 16:59 gfortran 10.2 and tests in debug mode Patrick Begou
@ 2021-02-06 17:18 ` Thomas Koenig
  2021-02-06 18:06   ` Patrick Begou
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2021-02-06 17:18 UTC (permalink / raw)
  To: Patrick Begou, fortran


Am 06.02.21 um 17:59 schrieb Patrick Begou via Fortran:

> In my mind, if the first condition in the if line is false, the second
> one must not be evaluated. But with gfortran 10.2 it is

That is a common fallacy, Fortran does not do short-circuting of
evaluation.

The right way to write this test is

        do i=1,4
           if (do_it > 0) then
              if (mod(i,do_it) .eq.0) then
              print*, "Do it!"

...

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gfortran 10.2 and tests in debug mode
  2021-02-06 17:18 ` Thomas Koenig
@ 2021-02-06 18:06   ` Patrick Begou
  0 siblings, 0 replies; 3+ messages in thread
From: Patrick Begou @ 2021-02-06 18:06 UTC (permalink / raw)
  To: Thomas Koenig, fortran

Thanks Thomas for this precision. For more than 30 years (since
fortran77) I was thinking that this syntax was right in Fortran (and it
always works). I never read about this in my fortran documentations.
In C language I think it is the case, may be the origin of my mistake...
I'll keep my changes in the the code.

Patrick

Le 06/02/2021 à 18:18, Thomas Koenig a écrit :
>
> Am 06.02.21 um 17:59 schrieb Patrick Begou via Fortran:
>
>> In my mind, if the first condition in the if line is false, the second
>> one must not be evaluated. But with gfortran 10.2 it is
>
> That is a common fallacy, Fortran does not do short-circuting of
> evaluation.
>
> The right way to write this test is
>
>        do i=1,4
>           if (do_it > 0) then
>              if (mod(i,do_it) .eq.0) then
>              print*, "Do it!"
>
> ...
>
> Best regards
>
>     Thomas



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-06 18:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-06 16:59 gfortran 10.2 and tests in debug mode Patrick Begou
2021-02-06 17:18 ` Thomas Koenig
2021-02-06 18:06   ` Patrick Begou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).