[Bug tree-optimization/15438] [3.5 Regression] miscompilation of simple testcase

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri May 14 22:36:00 GMT 2004


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-14 16:58 -------
I think the issue is that const is wrong here so glibc is wrong.
Yes I am right glibc is wrong:
const
Many functions do not examine any values except their arguments, and have no effects except the 
return value. Basically this is just slightly more strict class than the pure attribute above, since function 
is not allowed to read global memory.

They should instead be using the pure attribute:
pure
Many functions have no effects except the return value and their return value depends only on the 
parameters and/or global variables. Such a function can be subject to common subexpression 
elimination and loop optimization just as an arithmetic operator would be. These functions should be 
declared with the attribute pure. For example,
          int square (int) __attribute__ ((pure));
          


says that the hypothetical function square is safe to call fewer times than the program says.

Some of common examples of pure functions are strlen or memcmp. Interesting non-pure functions 
are functions with infinite loops or those depending on volatile memory or other system resource, that 
may change between two consecutive calls (such as feof in a multithreading environment).

The attribute pure is not implemented in GCC versions earlier than 2.96. 


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID
            Summary|miscompilation of simple    |[3.5 Regression]
                   |testcase                    |miscompilation of simple
                   |                            |testcase


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15438



More information about the Gcc-bugs mailing list