------- Additional Comments From liblit at cs dot wisc dot edu 2005-05-13 20:51 ------- Created an attachment (id=8886) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8886&action=view) preprocessed C code exhibiting the bug
The code in "redundant.i" shows the problem as described earlier. Perhaps I should explain a bit about what the code itself is doing. This code is much simplified from the original. The main idea seen here is that "global" is some global variable which we will be accessing many times. I know that this global is unaliased, but GCC does not. To help GCC along, I copy "global" into a local variable "local". The local serves as a local cache of the global, and GCC is able to show that "local" is unaliased even though it cannot show this for "global". At the top of descend(), we import the global into the local cache. We then do some work ("doSomeWork") using that local copy. In the original code this would have been lots of other inline code rather than just a call to an external function, and might have the effect of changing the value of the local cache. Ignore the "if" condition for now. At the very bottom of descend(), we export the local cache back out to the global variable. Now look inside that "if" condition. Before calling ourself recursively, we also need to export the local cache back out to the global. Just after that call, we import the global back into the local cache again. We actually need to do this before *any* call that might also use the global. It just so happens that the call in this case is recursive, and that the recursion is part of what triggers this bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21558