Patch to purify some functions.

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Thu Apr 20 12:54:00 GMT 2000


 > From: Robert Lipe <robertlipe@usa.net>
 > 
 > grahams wrote:
 > 
 > > Would it not be possible for the compiler to check that
 > > functions marked as pure are indeed pure.
 > 
 > If the compiler can figure out that something that is marked as pure
 > is pure, then the compiler should be able to figure out that something
 > should be marked as pure.  Therefore, if this is indeed possible, the
 > user shouldn't be marking them as pure and the compiler should be doing
 > it on its own without the user cluttering the code with such hints.

IIRC the automatic detection of this can only work for static
functions (maybe it already does?)  And I think then only for calls
which are made _after_ the static function is defined.  For extern
ones, the attribute is really necessary.

IMHO, I think these should be handled like attribute noreturn.  I.e.:

1.  Figure out when compiling functions whether it is impure and warn
if the attribute is incorrectly set.  There should be no false
positives.  When checking, calling an impure function means we are not
pure outselves.

2.  Internally mark appropriate libc functions within gcc as pure.

3.  Possibly add a -Wmissing-pure/-Wmissing-const flag to make the
compiler find places where we can add the attributes.

You may want to consolidate missing noreturn/pure/const into one -W flag.

(Note -Wmissing-noreturn is currently giving false positives because
it was broken by the tail call opts.  I think Zack has a patch to fix
it.  Don't let that throw you.)


 > Personally, I'm not a big fan of telling compilers things they should be
 > able to figure out.  I didn't like 'register', either. 
 > RJL

Agreed, except in this case, we can't figure it out.

--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


More information about the Gcc-patches mailing list