[Patch, Fortran] PR 57160: short-circuit IF only with -ffrontend-optimize
Janus Weil
janus@gcc.gnu.org
Mon Jul 23 17:11:00 GMT 2018
Hi Adam,
2018-07-23 9:40 GMT+02:00 Adam Hirst <adam@aphirst.karoo.co.uk>:
> On 20/07/18 22:37, Janus Weil wrote:
>>
>> Now, this PR (57160) is about code which relies on the
>> short-circuiting behavior. Since short-circuiting is not guaranteed by
>> the standard, such code is invalid. Generating a warning or an error
>> at compile-time is a bit harder here, though, since there are multiple
>> variations of such a situation, e.g.:
>> * ASSOCIATED(p) .AND. p%T
>> * ALLOCATED(a) .AND. a%T
>> * i<ubound(x) .AND. x(i)
>> * ...
>>
>> The suggestion in the PR was to do short-circuiting only with
>> optimization flags, but inhibit it with -O0, so that the faulty code
>> will run into a segfault (or runtime error) at least when
>> optimizations are disabled, and the problem can be identified.
>>
>> I find this suggestion very reasonable. It makes it possible to detect
>> invalid code at -O0, while keeping good performance for valid code at
>> -O{1,2,3}. Also it is technically very simple to implement, and it
>> immediately identified a faulty test case that has lived in the
>> testsuite for eleven years without being detected.
>
> One thing I'm not seeing in the original discussion was whether or not
> this should also count for -Og
good point!
> which certainly in my experience is
> (paired with -g) a common debug setting.
Agreed. I actually use it myself.
> I would err towards -Og here being paired with -O0, but I could see it
> being argued both ways - either way, I thought it might at least be
> worth making explicit?
Well, yes, the current documentation for -ffrontend-optimize is not
horribly explicit, but it does say: " Enabled by default by any -O
option." Technically that includes -Og, I guess.
Phenomenologically, it seems that -Og indeed behaves like -O{1,2,3} in
this respect. If one wanted to change that, one would probably do
this:
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c (revision 262908)
+++ gcc/fortran/options.c (working copy)
@@ -417,7 +417,7 @@
specified it directly. */
if (flag_frontend_optimize == -1)
- flag_frontend_optimize = optimize;
+ flag_frontend_optimize = optimize && !optimize_debug;
/* Same for front end loop interchange. */
I tend to agree with you that this might be a good idea, but I also
don't have a strong opinion here. (Alternatively one could leave
-ffrontend-optimize as is, and just couple the short-circuiting
behavior to "flag_frontend_optimize && !optimize_debug", but that
seems less attractive to me.) Maybe others can comment?
Cheers,
Janus
More information about the Fortran
mailing list