next up previous
Next: Pointers Up: Limitations and Future Work Previous: Multiple Compilation Units

Static Properties of Functions

Our analysis can detect two static properties of a function: being pure--having no side effects (for any argument values to the function)--or const--having no side effects and also not depending on global variables or values pointed to by pointer arguments (for any arguments). However, there may be functions that sometimes produce side effects (or depend on values in memory) but do not for some classes of input. For example, a ``safe-divide'' function that divided two integers or printed an error if the divisor were zero would be reusable (const) when the second argument was known to be non-zero. Our analysis will not detect these and GCC is not able to optimize calls to these functions.

Overcoming this limitation would require analysis for each function call rather than each function, would be more expensive and would not allow the called function to be analyzed separately ahead of time.

Figure 4: An example of a case where pointer analysis can help obtain less conservative results.
\begin{figure}\texttt{\\
\begin{tabbing}
int \=square(int n) \{\\
\>int i;\\
...
...t *ip = \\ \
\>*ip = n * n;\\
\>return i;\\
\}\\
\end{tabbing}}\end{figure}



Indrayana Rustandi 2003-12-04