This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Warnings with -fstrict-aliasing
Type: compile error Stage: commit review
Components: Build Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: Arfrever, bkabrda, christian.heimes, pitrou, python-dev, rhettinger, serhiy.storchaka, vstinner
Priority: low Keywords: patch

Created on 2013-05-21 08:32 by bkabrda, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tsc_strict_aliasing.patch christian.heimes, 2013-07-07 19:02 review
Messages (10)
msg189729 - (view) Author: Bohuslav "Slavek" Kabrda (bkabrda) * Date: 2013-05-21 08:32
Hi,
I'm getting these warnings with -fstrict-aliasing, compiling Python 3.3.2 (compiling with gcc 4.4.7):

/builddir/build/BUILD/Python-3.Python/ceval.c: In function 'PyEval_EvalFrameEx':
/builddir/build/BUILD/Python-3.Python/ceval.c:1006: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1007: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1008: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1009: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1249: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1258: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:1372: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2358: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2362: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2377: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2379: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2388: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2390: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2743: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2745: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2896: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:2909: warning: dereferencing type-punned pointer will break strict-aliasing rules
/builddir/build/BUILD/Python-3.Python/ceval.c:3035: warning: dereferencing type-punned pointer will break strict-aliasing rules

This seems to be quite serious, but I'm not a C expert, so I'd like to know whether this is a false positive or this is actually a dangerous bug.
Thanks.
msg189731 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2013-05-21 08:51
Your Python/ceval.c has custom patches applied. Line 1006 is a comment in unmodified Python/ceval.c in Python 3.3.2. This bug might be caused by your patches.

Alternatively it is a bug in GCC 4.4.7.
I get 0 warnings for unmodified Python/ceval.c with GCC 4.7.3.
msg189734 - (view) Author: Bohuslav "Slavek" Kabrda (bkabrda) * Date: 2013-05-21 09:07
Hmm, you're probably right. The problem seems to be in downstream redefinition of READ_TIMESTAMP. Sorry for the fuzz, closing.
msg189739 - (view) Author: Bohuslav "Slavek" Kabrda (bkabrda) * Date: 2013-05-21 09:59
Actually, this appears on vanilla Python 3.3 with -DWITH_TSC:

Python/ceval.c: In function ‘PyEval_EvalFrameEx’:
Python/ceval.c:986:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     READ_TIMESTAMP(inst0);
     ^
Python/ceval.c:987:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     READ_TIMESTAMP(inst1);
     ^
Python/ceval.c:988:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     READ_TIMESTAMP(loop0);
     ^
Python/ceval.c:989:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     READ_TIMESTAMP(loop1);
     ^
Python/ceval.c:1225:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(inst1);
             ^
Python/ceval.c:1234:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         READ_TIMESTAMP(loop0);
         ^
Python/ceval.c:1348:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         READ_TIMESTAMP(inst0);
         ^
Python/ceval.c:2334:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr0);
             ^
Python/ceval.c:2338:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr1);
             ^
Python/ceval.c:2353:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr0);
             ^
Python/ceval.c:2355:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr1);
             ^
Python/ceval.c:2364:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr0);
             ^
Python/ceval.c:2366:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr1);
             ^
Python/ceval.c:2719:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr0);
             ^
Python/ceval.c:2721:13: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             READ_TIMESTAMP(intr1);
             ^
Python/ceval.c:2872:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         READ_TIMESTAMP(inst1);
         ^
Python/ceval.c:2885:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
                     READ_TIMESTAMP(loop1);
                     ^
Python/ceval.c:3011:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         READ_TIMESTAMP(loop1);
         ^
msg192582 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-07 19:02
The warning is caused by the X86_64 code for timestamps:

#define READ_TIMESTAMP(val) \
    __asm__ __volatile__("rdtsc" : \
                         "=a" (((int*)&(val))[0]), "=d" (((int*)&(val))[1]));

The patch fixes the issue with two temp vars.
msg232473 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-12-11 12:21
LGTM.
msg232491 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-12-11 20:52
Looks good to me as well.
msg232515 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-12-12 07:52
+1
msg232535 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-12-12 12:20
New changeset 9565b56a4615 by Victor Stinner in branch '2.7':
Issue #18028: Fix aliasing issue in READ_TIMESTAMP() of ceval.c  on x86_64,
https://hg.python.org/cpython/rev/9565b56a4615

New changeset adb445578995 by Victor Stinner in branch '3.4':
Issue #18028: Fix aliasing issue in READ_TIMESTAMP() of ceval.c  on x86_64,
https://hg.python.org/cpython/rev/adb445578995
msg232536 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-12 12:22
3 core developers reviewed Christian's patch, so it also looks good to me :-) Since Christian looks to be busy, I commited his patch. Thanks Christian for your fix.

We might enable -fstrict-aliasing later, at least to compile Python core (not to build extensions).
History
Date User Action Args
2022-04-11 14:57:45adminsetgithub: 62228
2014-12-12 12:22:32vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg232536

resolution: fixed
2014-12-12 12:20:28python-devsetnosy: + python-dev
messages: + msg232535
2014-12-12 07:52:39rhettingersetnosy: + rhettinger
messages: + msg232515
2014-12-11 20:52:44pitrousetnosy: + pitrou
messages: + msg232491
2014-12-11 12:21:41serhiy.storchakasetversions: + Python 3.5, - Python 3.3
nosy: + serhiy.storchaka

messages: + msg232473

assignee: christian.heimes
stage: patch review -> commit review
2013-07-07 19:02:24christian.heimessetfiles: + tsc_strict_aliasing.patch
priority: normal -> low
type: compile error

versions: + Python 3.4
keywords: + patch
nosy: + christian.heimes

messages: + msg192582
stage: patch review
2013-05-21 09:59:36bkabrdasetstatus: closed -> open

messages: + msg189739
2013-05-21 09:07:55bkabrdasetstatus: open -> closed

messages: + msg189734
2013-05-21 08:51:25Arfreversetnosy: + Arfrever
messages: + msg189731
2013-05-21 08:32:22bkabrdacreate