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,

On Thu, 12 Jun 2003 law@redhat.com wrote:

> Given two invocations of a pure function with the same inputs, will the
> pure function always return the same value?

No, it can return different values each time.  For instance:

static int count;
void inc(void) { count++; }
int get(void) {return count;}

Here get() is a pure function whose return value depends on how often
inc() was called before.

> If the answer is no, then we'll need to distinguish between pure and
> const functions later -- simply clearing TREE_SIDE_EFFECTS would result
> in incorrect code.

I see.  But I guess this can be done?

> Is a pure function allowed to read volatile memory?

No.  Reading volatile mem is defined to have unpredictable side-effects.
A pure function is defined to have no side effects.  Therefore it can't
read volatile mem (and similar to "const" it also can't call other
non-pure functions).


Ciao,
Michael.


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