http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51218
--- Comment #18 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-11-21 20:21:01 UTC --- On Mon, Nov 21, 2011 at 08:02:20PM +0000, burnus at gcc dot gnu.org wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51218 > > --- Comment #17 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-21 > 20:02:20 UTC --- > (In reply to comment #16) > > One thing it relies on is that the compiler recognizes > > that the bad function are not pure, as they have a > > side effect (e.g. accessing module variable call_level). > > If a side effect is able to disable critical optimizations, > > then I'm optimistic that the code will work on most platforms. > > > > Now as promised, here's the reduced example: > > Thanks for the example! > > Untested patch: > > --- a/gcc/fortran/resolve.c > +++ b/gcc/fortran/resolve.c > @@ -3257,6 +3255,7 @@ pure_subroutine (gfc_code *c, gfc_symbol *sym) > else if (gfc_pure (NULL)) > gfc_error ("Subroutine call to '%s' at %L is not PURE", sym->name, > &c->loc); > + gfc_current_ns->proc_name->attr.implicit_pure = 0; > } Harald's example has function calls not subroutines. I would expect that you need to set this in pure_function as well. Also, does this type of change inhibit reason why implicit_pure was added in the first place?