This is the mail archive of the gcc-patches@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: [tree-ssa] Removing useless/redundant "const" calls



On Thursday, Jun 12, 2003, at 12:15 America/New_York, Zack Weinberg wrote:
This seems like an opportune moment to point out that calls to
noreturn functions shouldn't count as side effects when determining
whether functions are pure or const.

Example - if I have a square root function that starts with

if (arg < 0) abort ();

but has no other potential side effects, it should still be considered
const.

In Ada, subprograms in a pure library unit may raise exceptions, which is done by calling a no-return procedure. Indeed, the Ada math library is pure, while functions such as Sqrt are required to raise exceptions for negative arguments. Indeed, I see no reasons why there would be a conflict between pure functions, and calls to no-return subprograms or raising exceptions.

However, IIRC, there are places in tree-ssa that assume pure functions
do not raise exceptions.

BTW, If I speak about "pure" I use it in the Ada sense, see RM 10.2.1:

 18. If a library unit is declared pure, then the implementation is
     permitted to omit a call on a library-level subprogram of the
     library unit if the results are not needed after the call.
     Similarly, it may omit such a call and simply reuse the results
     produced by an earlier call on the same subprogram, provided that
     none of the parameters are of a limited type, and the addresses
     and values of all by-reference actual parameters, and the values
     of all by-copy-in actual parameters, are the same as they were at
     the earlier call. This permission applies even if the subprogram
     produces other side effects when called.

What is the exact definition of "pure" and "const" for GCC? The "definition"
in extend.texi is very informal and vague.


-Geert


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