Automatic inference of const/pure function attributes
Ian Lance Taylor
iant@google.com
Sat Jan 24 18:52:00 GMT 2009
Yang Zhang <yanghatespam@gmail.com> writes:
> Can gcc automatically determine that a function is const/pure (on a
> best-effort basis), instead of requiring the user to explicitly
> specify the attribute always? (I realize determining this may be
> difficult for certain functions, or the user may simply wish to
> specify this anyway regardless of the true nature of the function.)
Yes, gcc can and does do this, within a single source file. It only
works when gcc can prove that every function called by that function
is itself const or pure. In practice that means that it works
reliably for leaf functions, but if the pure/const function calls a
function defined in another source file then that other function must
be explicitly annotated.
When gcc implements whole program optimization in the future, this
will no doubt be extended to work between source files.
Ian
More information about the Gcc-help
mailing list