[Pyrex] gcc's -fstrict-aliasing optimization can break vtable construction in PyMODINIT_FUNC

Lenard Lindstrom len-l at telus.net
Sun Nov 25 06:36:02 CET 2007


Dan Gindikin wrote:
> Lenard Lindstrom:
>   
>> The problem is more complicated than strict aliasing.
>> The C compiler complains but the d.F() method call works  correctly.
>>     
>
> What gcc complaints were you seeing?
>
>   
For the following pyrex test code:

cdef class Base:
    cdef void F(self):
        print "Base"

cdef class Derived(Base):
    cdef void F(self):
        print "Derived"

cdef Derived d
d=Derived()

d.F() # <--- This in fact calls Base.F(), not Derived.F()

I get three gcc warnings:

warning: dereferencing type-punned pointer will break strict-aliasing rules

where pointers are cast to different data structures, e.g. from a 
derived class instance pointer to PyObject *.

> I too have seen this problem go away with other optimization flag sets, 
> but I thought and still think it most likely, that it's about the 
> aliasing. I think different optimization settings cause this particular 
> re-ordering of writes  to happen or not happen.
>
> You could easily be right of course, the story may not be as simple as that.
>
>   

"-O2" optimization includes -fstrict_aliasing but works. "-O3" adds 
-finline-functions, -fweb, -frename-registers and -funswitch-loops and 
fails.

-- 
Lenard Lindstrom
<len-l at telus.net>




More information about the Pyrex mailing list