[Patch, Fortran] PR 85599: warn about short-circuiting of logical expressions for non-pure functions
Janus Weil
janus@gcc.gnu.org
Tue Jul 17 14:32:00 GMT 2018
2018-07-17 9:52 GMT+02:00 Janus Weil <janus@gcc.gnu.org>:
>> 2018-07-16 21:50 GMT+02:00 Thomas Koenig <tkoenig@netcologne.de>:
>>> What I would suggest is to enable -Wfunction-eliminiation with
>>> -Wextra and also use that for your new warning.
>>
>> Thanks for the comments. Makes sense. Updated patch attached.
>
>
> Huh, after actually trying -Wfunction-elimination, I'm not so sure any
> more if it really makes sense to throw the new warnings in there,
> mainly for two reasons:
>
> a) -Wfunction-elimination is slightly different, in that it warns
> about removing *any* kind of function, not just impure ones. This
> makes it pretty verbose, and I'm not sure why one would need to know
> if a pure function call is removed.
> b) It gives warnings on places that I don't understand. Simple example:
>
> subroutine sub(r)
> implicit none
> real, intent(in) :: r
> if ((abs(r) > 1e6) .or. (abs(r) < 1e-6)) then
> print *, "rrr"
> end if
> end
>
> Compiling this with "gfortran-8 -O1 -Wfunction-elimination" gives me:
>
> if ((abs(r) > 1e6) .or. (abs(r) < 1e-6)) then
> 1
> Warning: Removing call to function ‘abs’ at (1) [-Wfunction-elimination]
>
>
> Why can I remove the call to ABS there? If I read the dump correctly,
> then the two calls to ABS are optimized into a single one, which is
> used for both comparisons via a temporary. Is that what the warning is
> trying to tell me? And if yes, why should I care (if the function is
> pure)? The middle-end certainly does tons of optimizations that
> rearrange various expressions, without warning me about it ...
>
> In other words: Does it make sense to tone down
> -Wfunction-elimination, by only warning about impure functions?
Here is an update of the patch which does that. Regtesting now ...
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr85599_v6.diff
Type: text/x-patch
Size: 8262 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180717/bbd1e882/attachment.bin>
More information about the Fortran
mailing list