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.

Title: Apple's clang 2.1 (xcode 4.1, OSX 10.7) optimizer miscompiles intobject.c
Type: Stage:
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: int_pow() implementation is incorrect
View: 12973
Assigned To: Nosy List: deadshort, mark.dickinson, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2011-08-06 02:46 by deadshort, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
seqpoint.c deadshort, 2011-08-06 02:46
Messages (9)
msg141701 - (view) Author: deadshort (deadshort) Date: 2011-08-06 02:46
Apple Radar ticket 9908625 has been filed. The clang 2.1 optimizer causes overflows in Object/intobject.c:int_pow() to be missed, so 2**63 turns into a negative integer. The attached test program narrows it down. llvm-gcc is fine, so this ticket is mostly an FYI.

idiotbox:Python-2.7.2 cloomis$ ./seqpoint-OK 4000000000 4000000000
a=4000000000, b=4000000000, c(a*b)=-2446744073709551616, c/b=-611686018
overflow detected: 1

  to turn into:

idiotbox:Python-2.7.2 cloomis$ ./seqpoint 4294967296 4200000000
a=4294967296, b=4200000000, c(a*b)=-407881430509551616, c/b=4294967296
overflow detected: 0
msg141702 - (view) Author: deadshort (deadshort) Date: 2011-08-06 02:48
Blecch: cut-o.
The bad case should have been the matching:

idiotbox:Python-2.7.2 cloomis$ ./seqpoint 4000000000 4000000000
a=4000000000, b=4000000000, c(a*b)=-2446744073709551616, c/b=4000000000
overflow detected: 0
msg141804 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-08-08 21:24
Have you checked if -fwrapv is in the list of compiler arguments in the generated makefile?

There is an open issue about adding that flag when clang is used as the compiler (the flag is already used for gcc). The flag is necessary because the example code contains an integer overflow and that is undefined behavior according to the C standard.
msg141809 - (view) Author: deadshort (deadshort) Date: 2011-08-09 06:42
Yup, that was it. Something new learnt. Thanks.

Not sure how to have configure spot that clang needs the flag. OK, the configure stanza for gcc is hardly general; maybe trying $(CC) -fwrapv and  keeping the flag if that does not blow up on the pad? But I guess that other ticket takes care of that.
msg141900 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-08-11 11:45
If there's dependence on undefined behaviour (from overflow of signed integer operations) in intobject.c, I'd call that a bug.  I've been trying to remove similar overflow checks from the Python source when I've encountered them, but there are still a good few left.
msg141902 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-08-11 12:16
Clang has an option "-fcatch-undefined-behavior" that might help in locating other locations where we use undefined behavior.
msg180610 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-01-25 19:23
Is this still a problem in clang 3.2?
msg180618 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-01-25 20:08
I believe the int_pow issue has been resolved, so this bug shouldn't show up in any of the current branches, regardless of which version of Clang is used.
msg180619 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-01-25 20:09
Issue #12973 is the one that led to the eventual fix.  Closing this as a duplicate.
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56910
2013-01-25 20:09:25mark.dickinsonsetstatus: open -> closed
superseder: int_pow() implementation is incorrect
resolution: duplicate
messages: + msg180619
2013-01-25 20:08:02mark.dickinsonsetmessages: + msg180618
2013-01-25 19:24:10brett.cannonsetstatus: pending -> open
nosy: - brett.cannon
2013-01-25 19:23:58brett.cannonsetstatus: open -> pending
nosy: brett.cannon, ronaldoussoren, mark.dickinson, ned.deily, deadshort
messages: + msg180610
2011-08-11 12:16:07ronaldoussorensetmessages: + msg141902
2011-08-11 11:48:32petri.lehtinensetfiles: - unnamed
2011-08-11 11:45:32mark.dickinsonsetnosy: + mark.dickinson
messages: + msg141900
2011-08-09 06:42:27deadshortsetmessages: + msg141809
2011-08-08 22:17:47brett.cannonsetnosy: + brett.cannon
2011-08-08 21:24:13ronaldoussorensetfiles: + unnamed

messages: + msg141804
2011-08-06 02:52:36ned.deilysetnosy: + ronaldoussoren, ned.deily
2011-08-06 02:48:44deadshortsetmessages: + msg141702
2011-08-06 02:46:58deadshortcreate