[tree-ssa] Removing useless/redundant "const" calls
Fergus Henderson
fjh@cs.mu.oz.au
Thu Jun 12 17:16:00 GMT 2003
On 12-Jun-2003, Zack Weinberg <zack@codesourcery.com> 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.
That is not correct in general.
> 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.
Doing that would violate the C standard, and would potentially create
security holes. Consider, for example:
#define ARRAY_SIZE 10
int array[ARRAY_SIZE];
void checkbounds(int arg) {
if (arg < 0) abort();
if (arg > ARRAY_SIZE) abort();
}
int set_array(int posn, int val) {
checkbounds(posn);
array[posn] = val;
}
If the call to checkbounds() gets optimized away, then the resulting
code may be prone to buffer overflow attacks.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the Gcc-patches
mailing list