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


Fergus Henderson <fjh@cs.mu.oz.au> writes:

> 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.

I disagree.

> 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;
> 	}

checkbounds() returns no value, so it must be used for its side
effects, so it isn't pure.

zw


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