This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a question about const and pure functions.



On Nov 11, 2004, at 16:05, Geoffrey Keating wrote:


All this sounds like a great idea.

(I would caution, though, that really you should check that a recursive function terminates. You may be able to finesse the issue on the grounds that a recursive function that doesn't terminate will usually eventually run out of stack and terminate that way.)

This of course will not hold for the case of where the recursion is optimized
away, or sibling calls prevent stack growth.


Also, even if all recursive functions eventually terminate, a stack
overflow does not necessarily have to be erroneous (undefined) execution.
For example, Ada requires Storage_Error to be raised in such cases, and
this is implemented through -fstack-check.


The following procedure should never output FAILED:

  with Some_Const_Function_That_Never_Returns;
  with Text_IO;
  procedure Hello is
     X : Integer;

  begin
     X := Some_Recursive_Const_Function_That_Never_Returns;
     Text_IO.Put_Line ("FAILED");
  end;

This function could either terminate the program with a Storage_Error
or run for indefinite time. Of course, I'm assuming here that
Some_Const_Function_That_Never_Returns was not declared to be const,
but would be detected as such with your suggestion.

Note however, that Some_Recursive_Const_Function_That_Never_Returns
still can be CSE'd, as long as at least one call remains. Even without
-fstack-check, it is highly dubious to back-propagate information
about execution becoming undefined.

-Geert


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]