https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109914
--- Comment #5 from Jan Hubicka <hubicka at ucw dot cz> --- > (In reply to Jan Hubicka from comment #2) > > The reason why gcc warns is that it is unable to prove that the function is > > always finite. > > I don't see why finiteness matters. If a pure function returns the first time > it's called, and if there's no change to visible state after that, it should > return the second time with the same value. And if the pure function didn't > return the first time evaluation won't even get to the second time. So common > subexpression elimination (which is the point of 'pure') will work even if a > pure function does not return. yes, however both const and pure attributes allows compiler to also remove the call if return value is unused. So here finiteness matters. > > C23 has standardized this stuff with the [[reproducible]] attribute, and as > far > as I can see (the wording is admittedly murky) C23 does not impose a > finiteness > constraint on reproducible functions. If my reading of C23 is correct, GCC > should not impose finiteness constraints on reproducible functions when it > gets > around to implementing [[reproducible]], and if [[reproducible]] and > __attribute__((pure)) are supposed to be the same thing then GCC should drop > the finiteness constraint on pure functions as well. Interesting, I did not notice that. These notions are not the same. However ipa-mod-ref internally knows if function has side effects (i.e. can be infinite) and if it is reproducible (i.e. will do same thing when called again) and we could use this for redundancy elimination if that pass is extended to remove redundant calls. So I guess adding reproducible attribute in addition to pure and const makes sense. > > > I agree with Bruno's main point that none of this stuff should matter for > static functions. --suggest-attribute=* warnings are useless chatter for > static > functions. It helps the compiler to solve the halting problem.