[tree-ssa] Removing useless/redundant "const" calls
Geert Bosch
bosch@gnat.com
Thu Jun 12 17:40:00 GMT 2003
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
More information about the Gcc-patches
mailing list