[Bug fortran/85599] invalid optimization: function not always evaluated in logical expression

janus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 2 09:49:00 GMT 2018


--- Comment #5 from janus at gcc dot gnu.org ---
Here is a variant of the original test case, now with a PURE procedure:

program lazy

   logical :: flag

   flag = .false.
   flag = check() .and. flag
   flag = flag .and. check()


   pure logical function check()
      check = .true.
   end function


In this case I would think it's perfectly valid to optimize away both calls to
'check', in particular because there is actually no way to check for the user
whether the function 'check' is being called (other than looking at the
assembly code etc).

However, I could not find any distinctions between pure and impure functions in
the standard, when it comes to the question of function evaluation and
optimizations. Any pointers appreciated.

More information about the Gcc-bugs mailing list