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


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


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