This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Removing useless/redundant "const" calls
- From: Geert Bosch <bosch at gnat dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Michael Matz <matz at suse dot de>, law at redhat dot com,gcc-patches at gcc dot gnu dot org
- Date: Thu, 12 Jun 2003 13:35:41 -0400
- Subject: 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