Bug 1392247 - ocaml-zarith fails tests on ppc64le
Summary: ocaml-zarith fails tests on ppc64le
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: ocaml-zarith
Version: 26
Hardware: ppc64le
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jerry James
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-11-06 20:29 UTC by Richard W.M. Jones
Modified: 2018-05-29 11:46 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-05-29 11:46:39 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Richard W.M. Jones 2016-11-06 20:29:27 UTC
Description of problem:

These appear to be genuine problems with the software on ppc64le:

$ ./zq.exe > /tmp/output
$ diff -ur zq.output64 /tmp/output 
--- zq.output64	2015-11-09 16:23:00.000000000 -0500
+++ /tmp/output	2016-11-06 15:25:53.403804570 -0500
@@ -283,7 +283,7 @@
 of_float 1.
  = 1
 of_float -1.
- = -1
+ = 0
 of_float pi
  = 3
 of_float 2^30
@@ -295,13 +295,13 @@
 of_float 2^33
  = 8589934592
 of_float -2^30
- = -1073741824
+ = 0
 of_float -2^31
- = -2147483648
+ = 0
 of_float -2^32
- = -4294967296
+ = 0
 of_float -2^33
- = -8589934592
+ = 0
 of_float 2^61
  = 2305843009213693952
 of_float 2^62
@@ -313,7 +313,7 @@
 of_float 2^65
  = 36893488147419103232
 of_float -2^61
- = -2305843009213693952
+ = 0
 of_float -2^62
  = -4611686018427387904
 of_float -2^63
@@ -337,7 +337,7 @@
 of_float 200.5
  = 200
 of_float -200.5
- = -200
+ = 0
 to_float 0
  = 0.000000
 to_float 1


Version-Release number of selected component (if applicable):

ocaml-zarith-1.4.1-3.fc26

How reproducible:

100%

Steps to Reproduce:
1. Run the %check section in the usual RPM build.

Comment 1 Jerry James 2016-11-07 04:00:10 UTC
Are you building in a side tag?  I just tried building in mock on one of the Brno openpower hub ppc64le boxes, and even after wiping out the mock cache and building with --enablerepo=local I'm still getting ocaml 4.02.3-3.fc25.  Perhaps the mirrors haven't caught up yet.

The build succeeds and all tests pass with that version of ocaml, by the way.

Comment 2 Richard W.M. Jones 2016-11-07 10:07:53 UTC
Yes you need to install the f26-ocaml packages.  Try adding the
following repo to your machine:

$ cat /etc/yum.repos.d/tmp-f26-ocaml.repo
[f26-ocaml]
name=f26-ocaml
baseurl=https://kojipkgs.fedoraproject.org/repos/f26-ocaml/latest/$basearch/
enabled=1
gpgcheck=0

Comment 3 Richard W.M. Jones 2016-11-07 14:29:29 UTC
I still don't really understand what's going on here, but the problem
appears to happen in the Val_long(x) cast here:

https://github.com/bobot/zarith/blob/master/caml_z.c#L524

I added lots of debugging around this part of the code.  On ppc64 (thought
to be correct):

x = -1
Z_MIN_INT_FL = -4611686018427383808 Z_MAX_INT_FL = 4611686018427383808
x as Long = -1
(uintnat)(x) = 18446744073709551615
(uintnat)(x) << 1 = 18446744073709551614
(intnat) ((uintnat)(x) << 1) = -2
((intnat) ((uintnat)(x) << 1)) + 1 = -1

On ppc64le (incorrect):

x = -1
Z_MIN_INT_FL = -4611686018427383808 Z_MAX_INT_FL = 4611686018427383808
x as Long = 1
(uintnat)(x) = 0
(uintnat)(x) << 1 = 0
(intnat) ((uintnat)(x) << 1) = 0
((intnat) ((uintnat)(x) << 1)) + 1 = 1


Why on earth does (uintnat)(-1) return 0?  That makes no sense to me.
(I'm assuming that uintnat is unsigned long)

Comment 4 Richard W.M. Jones 2016-11-07 15:47:04 UTC
OK so as far as I can tell this is undefined behaviour in C:

https://stackoverflow.com/questions/10541200/is-the-behaviour-of-casting-a-negative-double-to-unsigned-int-defined-in-the-c-s

https://gcc.gnu.org/ml/gcc-help/2010-04/msg00140.html

and therefore the Zarith code is wrong.

Comment 6 Richard W.M. Jones 2016-11-07 16:11:03 UTC
This patch fixes things for me.  I'm going to drop it into our
ocaml-zarith package to get things moving along.

diff --git a/caml_z.c b/caml_z.c
index b690a2a..42d3850 100644
--- a/caml_z.c
+++ b/caml_z.c
@@ -521,7 +521,7 @@ CAMLprim value ml_z_of_float(value v)
   Z_MARK_OP;
   x = Double_val(v);
 #if Z_USE_NATINT
-  if (x >= Z_MIN_INT_FL && x <= Z_MAX_INT_FL) return Val_long(x);
+  if (x >= Z_MIN_INT_FL && x <= Z_MAX_INT_FL) return Val_long((intnat)x);
 #endif
   Z_MARK_SLOW;
 #ifdef ARCH_ALIGN_INT64

Comment 7 Jerry James 2016-11-08 04:26:45 UTC
Thank you for figuring this out, Richard.  I will send your patch upstream, with attribution.

Comment 8 Richard W.M. Jones 2016-11-08 08:47:20 UTC
Hi Jerry, there is a thread on caml-list where this was discussed:

https://sympa.inria.fr/sympa/arc/caml-list/2016-11/msg00013.html

So Xavier is aware of the problem/fix.  But it would be good to make
sure a patch gets added upstream and not forgotten about.

Comment 10 Fedora End Of Life 2017-02-28 10:34:01 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle.
Changing version to '26'.

Comment 11 Fedora End Of Life 2018-05-03 08:00:40 UTC
This message is a reminder that Fedora 26 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 26. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '26'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 26 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 12 Fedora End Of Life 2018-05-29 11:46:39 UTC
Fedora 26 changed to end-of-life (EOL) status on 2018-05-29. Fedora 26
is no longer maintained, which means that it will not receive any
further security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


Note You need to log in before you can comment on or make changes to this bug.