[tree-ssa] Removing useless/redundant "const" calls

Roger Sayle roger@eyesopen.com
Fri Jun 13 04:07:00 GMT 2003


Hi Zack,
> 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.

I think its important to reach consensus on this and document GCC's
interpretation of pure and const functions.  For example, there are
currently optimizations in GCC that avoid emitting calls to pure or
const functions if the result isn't used.  Obviously, this optimization
is incorrect if the function may not return or has other side-effects.

Indeed, I recall that not returning from a function *was* deemed to
be a side-effect, the last time this went around on gcc-patches/gcc.
[Together with the fact that Ada used a slightly different definition
of pure/const, concerning whether memory other than that pointed to
by function arguments could be accessed].

Everything is currently consistent within GCC that noreturn functions
aren't pure/const, and that a function is pure/const if it only calls
functions that are pure/const.  i.e. calling abort() currently implies
impure/side-effecting in GCC's perception routines.

If you think its a good idea to change this definition, I'm sure
it wouldn't be too hard to change all of the places that follow the
current "noreturn=impure" semantics.  However, looking at libc's
functions, the current semantics would appear to be far more useful
in practice, i.e. (void)strlen(foo) is really a no-op.

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list