[Python-Dev] Heads up: Apple llvm gcc 4.2 miscompiles PEP 393

martin at v.loewis.de martin at v.loewis.de
Wed Sep 28 13:24:22 CEST 2011


The gcc that Apple ships with the Lion SDK (not sure what Xcode  
version that is)
miscompiles Python now. I've reported this to Apple as bug 10143715;  
not sure whether
there is a public link to this bug report.

In essence, the code

typedef struct {
     long length;
     long hash;
     int state;
     int *wstr;
} PyASCIIObject;

typedef struct {
     PyASCIIObject _base;
     long utf8_length;

     char *utf8;
     long wstr_length;

} PyCompactUnicodeObject;

void *_PyUnicode_compact_data(void *unicode) {
     return ((((PyASCIIObject*)unicode)->state & 0x20) ?
             ((void*)((PyASCIIObject*)(unicode) + 1)) :
             ((void*)((PyCompactUnicodeObject*)(unicode) + 1)));
}

miscompiles (with -O2 -fomit-frame-pointer) to


__PyUnicode_compact_data:
Leh_func_begin1:
         leaq    32(%rdi), %rax
         ret

The compiler version is

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)

This unconditionally assumes that sizeof(PyASCIIObject) needs to be
added to unicode, independent of whether the state bit is set or not.

I'm not aware of a work-around in the code. My work-around is to use gcc-4.0,
which is still available on my system from an earlier Xcode installation
(in /Developer-3.2.6)

Regards,
Martin




More information about the Python-Dev mailing list