Issue 12701: Apple's clang 2.1 (xcode 4.1, OSX 10.7) optimizer miscompiles intobject.c (original) (raw)

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

Files
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.
History
Date User Action Args
2022-04-11 14:57:20 admin set github: 56910
2013-01-25 20:09:25 mark.dickinson set status: open -> closedsuperseder: int_pow() implementation is incorrectresolution: duplicatemessages: +
2013-01-25 20:08:02 mark.dickinson set messages: +
2013-01-25 19:24:10 brett.cannon set status: pending -> opennosy: - brett.cannon
2013-01-25 19:23:58 brett.cannon set status: open -> pendingnosy:brett.cannon, ronaldoussoren, mark.dickinson, ned.deily, deadshortmessages: +
2011-08-11 12:16:07 ronaldoussoren set messages: +
2011-08-11 11:48:32 petri.lehtinen set files: - unnamed
2011-08-11 11:45:32 mark.dickinson set nosy: + mark.dickinsonmessages: +
2011-08-09 06:42:27 deadshort set messages: +
2011-08-08 22:17:47 brett.cannon set nosy: + brett.cannon
2011-08-08 21:24:13 ronaldoussoren set files: + unnamedmessages: +
2011-08-06 02:52:36 ned.deily set nosy: + ronaldoussoren, ned.deily
2011-08-06 02:48:44 deadshort set messages: +
2011-08-06 02:46:58 deadshort create