summaryrefslogtreecommitdiff
path: root/numpy/core/src/scalarmathmodule.c.src
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2010-11-11 21:35:26 -0800
committerCharles Harris <charlesr.harris@gmail.com>2010-11-15 20:46:15 -0700
commit72a702d22cfcdba0346670defe887801c0e53eaf (patch)
tree7817b223caba89c9de425b84c3027114773d70ee /numpy/core/src/scalarmathmodule.c.src
parentd1a184c1a112ffbaa553915c043c2b6851e4fc91 (diff)
downloadnumpy-72a702d22cfcdba0346670defe887801c0e53eaf.tar.gz
BUG: core: Make scalar output volatile to prevent incorrect optimizer reordering (#1671)
Diffstat (limited to 'numpy/core/src/scalarmathmodule.c.src')
-rw-r--r--numpy/core/src/scalarmathmodule.c.src12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src
index 6913f517d..c4e6263ba 100644
--- a/numpy/core/src/scalarmathmodule.c.src
+++ b/numpy/core/src/scalarmathmodule.c.src
@@ -651,7 +651,13 @@ static PyObject *
{
PyObject *ret;
@name@ arg1, arg2;
- @otyp@ out;
+ /*
+ * NOTE: In gcc >= 4.1, the compiler will reorder floating point operations and
+ * floating point error state checks. In particular, the arithmetic operations
+ * were being reordered so that the errors weren't caught. Declaring this output
+ * variable volatile was the minimal fix for the issue. (Ticket #1671)
+ */
+ volatile @otyp@ out;
#if @twoout@
@otyp@ out2;
PyObject *obj;
@@ -692,9 +698,9 @@ static PyObject *
* as a function call.
*/
#if @twoout@
- @name@_ctype_@oper@(arg1, arg2, &out, &out2);
+ @name@_ctype_@oper@(arg1, arg2, (@otyp@ *)&out, &out2);
#else
- @name@_ctype_@oper@(arg1, arg2, &out);
+ @name@_ctype_@oper@(arg1, arg2, (@otyp@ *)&out);
#endif
#if @fperr@