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: Decimal module yields incorrect results when Python compiled with clang
Type: behavior Stage: resolved
Components: Build, Installation, Library (Lib), macOS Versions: Python 2.7, Python 2.6, 3rd party
process
Status: closed Resolution: duplicate
Dependencies: Superseder: [PATCH] Configure should enable -fwrapv for clang
View: 11149
Assigned To: ned.deily Nosy List: josharian, mark.dickinson, ned.deily, ronaldoussoren, skrah
Priority: normal Keywords: patch

Created on 2011-09-29 17:27 by josharian, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
llvm-gcc-fwrapv.diff skrah, 2011-09-29 20:41
Messages (5)
msg144604 - (view) Author: Joshua Bleecher Snyder (josharian) Date: 2011-09-29 17:27
When Python is compiled on OS X with llvm, the decimal module behaves erratically (simple calculations are wrong, most doctests fail). This was originally reported here:

http://stackoverflow.com/questions/7590137/dividing-decimals-yields-invalid-results-in-python-2-5-to-2-7

and the compiler dependency was tracked down here:

https://trac.macports.org/ticket/31444

Although it looks like MacPorts is going to force use of gcc, it'd still be better for Python to behave correctly when compiled with llvm.

Possibly related to http://bugs.python.org/issue11149?
msg144615 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-09-29 19:17
> Possibly related to http://bugs.python.org/issue11149?

Maybe I missed it in the links you gave, but that is easily
settled by compiling with and without -fwrapv.
msg144623 - (view) Author: Joshua Bleecher Snyder (josharian) Date: 2011-09-29 19:45
>> Possibly related to http://bugs.python.org/issue11149?

> Maybe I missed it in the links you gave, but that is easily
> settled by compiling with and without -fwrapv.

Apologies -- I didn't do enough homework on this one. Yes, I can confirm that compiling with -fwrapv solves this issue. Not sure whether that makes this bug a straight duplicate of http://bugs.python.org/issue11149...
msg144637 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-09-29 20:41
It's more a straight duplicate of #12973, but the underlying cause
(signed integer overflow) is the same. For people who are finding
this via a search engine: A lot of bugs have been fixed in #12973,
but even if the test suite passes without -fwrapv it is *still* recommended to use -fwrapv.


Could anyone test if the attached patch works for llvm-gcc?
msg144653 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-09-29 22:31
There is some confusion here, I think. As best as I can tell, the original problem reported in the Stackoverflow question and to MacPorts involved using the clang compiler, not llvm-gcc and the Decimal problem reported here was only ever a problem when using clang.  It's not an issue when using Apple's llvm-gcc compiler because the pre-#11149 configure test works properly with llvm-gcc.  That test looks for "-fwrapv" in the compiler help string:

$ llvm-gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ llvm-gcc -v --help 2>/dev/null | grep -- -fwrapv
  -fwrapv                     Assume signed arithmetic overflow wraps around
$ gcc-4.2 --version
i686-apple-darwin11-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc-4.2 -v --help 2>/dev/null | grep -- -fwrapv
  -fwrapv                     Assume signed arithmetic overflow wraps around
$ clang --version
Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.1.0
Thread model: posix
$ clang -v --help 2>/dev/null | grep -- -fwrapv

The above was using the 3 Apple-supplied compilers with the OS X 10.7 (Lion) version of Xcode 4.1 (Build version 4B110).  The 10.6 compiler versions should work the same way.

So this issue should be closed as a duplicate of Issue11149.  I'm setting it to pending and will close it if there are no objections.
History
Date User Action Args
2022-04-11 14:57:22adminsetgithub: 57270
2011-10-04 22:29:31ned.deilysetstatus: pending -> closed
assignee: ronaldoussoren -> ned.deily
title: Decimal module yields incorrect results when Python compiled with llvm -> Decimal module yields incorrect results when Python compiled with clang
stage: resolved
2011-09-29 22:31:13ned.deilysetstatus: open -> pending
resolution: duplicate
superseder: [PATCH] Configure should enable -fwrapv for clang
messages: + msg144653
2011-09-29 20:55:36mark.dickinsonsetnosy: + mark.dickinson
2011-09-29 20:41:38skrahsetfiles: + llvm-gcc-fwrapv.diff
keywords: + patch
messages: + msg144637
2011-09-29 19:52:00ned.deilysetnosy: + ned.deily
2011-09-29 19:45:44joshariansetmessages: + msg144623
2011-09-29 19:17:28skrahsetnosy: + skrah
messages: + msg144615
2011-09-29 17:27:44joshariancreate