Opened 12 years ago

Closed 9 years ago

#910 closed Bugs (worksforme)

gcc strict-aliasing problems with python

Reported by: kbarrett Owned by: Dave Abrahams
Milestone: Boost 1.36.0 Component: python USE GITHUB
Version: Boost 1.34.0 Severity: Cosmetic
Keywords: Cc:

Description (last modified by Dave Abrahams)

With the Boost 1.34.0 beta release candidate, and also with Boost 1.33.1, and probably before that too, building Boost.Python in release mode with a recent version of gcc (4.x) generates several occurrences of warnings:

"dereferencing type-punned pointer will break strict aliasing rules"

Beginning with Python 2.3 and at least through Python 2.5, when building Python with gcc, the gcc option -fno-strict-aliasing is used. So clearly the Python developers don't consider Python to be strict-aliasing correct (or else don't trust gcc's strict-aliasing analysis).

The result of not being strict-aliasing correct when gcc's strict aliasing option is enabled (which I think is the default for gcc 4.0 onward, at least at high optimization levels) is that the compiler may generate non-working code.

I don't have any specific evidence that the warnings from compiling Boost.Python indicate actual problems. These warnings may appear without there being any actual code generation differences. Unfortunately, that may vary from one version of gcc to another. Even worse, gcc may fail to generate warnings in cases where it does indeed generate non-working code. The best method I know of for finding instances of code broken by strict-aliasing based optimizations is to compile with and without that option, compare the generated code, and carefully examine the places that are different, with some differences being seemingly harmless. In other words, a very difficult and error-prone process.

I recommend that building Boost.Python with recent versions of gcc similarly supply the -fno-strict-aliasing option, and that it should also be used when compiling code that uses Boost.Python.

Change History (4)

comment:1 Changed 12 years ago by Dave Abrahams

Description: modified (diff)
Owner: changed from david_abrahams to Dave Abrahams
Severity: Showstopper
Status: assignednew

comment:2 Changed 12 years ago by Dave Abrahams

Description: modified (diff)
Milestone: Boost 1.35.0
Severity: ShowstopperCosmetic
Status: newassigned
Version: Nonerelease 1.34.0

comment:3 Changed 9 years ago by Dave Abrahams

If we could find a way to do this everywhere except Py3K, it would be ideal.

comment:4 Changed 9 years ago by Dave Abrahams

Resolution: Noneworksforme
Status: assignedclosed
Note: See TracTickets for help on using tickets.