This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/85599] invalid optimization: function not always evaluated in logical expression
- From: "janus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 02 May 2018 09:48:23 +0000
- Subject: [Bug fortran/85599] invalid optimization: function not always evaluated in logical expression
- Auto-submitted: auto-generated
- References: <bug-85599-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85599
--- 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()
contains
pure logical function check()
check = .true.
end function
end
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.