Sometimes, I would also like an attribute to say "no content of parameter-pointers" are
changed by a function, in fact nothing important is changed in memory by a function.
The main example would be printf(), or any function name used to print a debugging string -
with variable number of argument that cannot be prefixed by "const"
(we cannot compile "void dbgprintf (const char *, const ...);").
Then, if the compiler see some code like:
if (error)
dbgprintf ("here is the context address %x %s %s\n", &s1, s1, s2);
it has anyway to update in memory all content of pointer passed, but it does not have to
reload all those values to register after the call.
The main problem of those dbgprintf() is that there may be a lot of them, and it would be
nice if they did not interfer too much with execution time or other optimisation. True that
for x86 there is not enough register to notice the problem, but it is bad to see a lot of
unused register on other arch because the compiler has to keep in sync the memory and
registers too often.
Posted Jun 15, 2008 12:34 UTC (Sun) by nix (subscriber, #2304)
[Link]
Thanks to rarely-used glibc extensions, printf() and friends must be
assumed by optimizers to be able to change *anything*, both because the
information could be sent to a custom stream (-> calling arbitrary
functions), and because they can contain specifiers for which custom
conversion have been defined (-> calling arbitrary functions).