Euphoria Ticket #874: 4.05 fails bitwise operations on OS X

See http://openeuphoria.org/forum/121825.wc

Currently 32-bit Euphoria has 31-bit integers, and it can perform bitwise operations on integers up to 32 bits in size. Bitwise operations on integers larger than 32 bits produce incorrect results.

Integers which are 32 bits in size are stored as doubles. In order to preserve all 32 bits, the C backend has to cast the double to a C integer (long or unsigned long), perform the operation, and then possibly store it back to a double.

The C standard says that casting a double to a long that is too big to fit into the long is undefined, and that casting double that is too big or is negative to an unsigned long is undefined.

There is a bug in the Euphoria C backend which relies on this undefined behavior working a certain way. The fact that it worked until now is why it wasn't caught until we started moving into ARM and OS X platforms. The bug manifests itself as incorrect results from bitwise operations when the arguments were negative or were larger than 31 bits.

Details

Type: Bug Report Severity: Normal Category: Interpreter
Assigned To: jaygade Status: New Reported Release:
Fixed in SVN #: View VCS: none Milestone:

1. Comment by jaygade Jun 11, 2013

See: hg:euphoria/rev/74222c439548

changeset: 6122:74222c439548 branch: 4.0 tag: tip parent: 6120:cb5c7358ed9d user: Jason Gade <jaygade@yahoo.com> date: Tue Jun 11 18:53:03 2013 -0700 files: source/Makefile.gnu source/configure description: Added -mno-sse to gcc options for OS X to avoid double<>long conversion problems. See ticket:874

2. Comment by jaygade Jul 11, 2013

See: hg:euphoria/rev/40fda2942ba9

changeset: 6131:40fda2942ba9 user: Jason Gade <jaygade@yahoo.com> date: Tue Jul 09 23:51:34 2013 -0700 files: include/euphoria.h include/std/filesys.e include/std/locale.e source/be_callc.c source/be_execute.c source/be_machine.c source/be_machine.h source/be_pcre.c source/be_rterror.c source/be_runtime.c source/be_runtime.h source/be_socket.c source/compile.e source/execute.h source/global.e source/test818.c description: ticket:874 work in progress, plus tickets 804-817.

3. Comment by jaygade Jul 11, 2013

See: hg:euphoria/rev/aa5d035acbf7

changeset: 6132:aa5d035acbf7 user: Jason Gade <jaygade@yahoo.com> date: Wed Jul 10 22:07:50 2013 -0700 files: include/euphoria.h source/be_callc.c source/be_execute.c source/be_machine.c source/be_pcre.c source/be_runtime.c source/be_socket.c source/compile.e source/execute.h description: ticket:804 and ticket:874, fixed casting problems. Work in progress.

4. Comment by jaygade Jul 11, 2013

See: hg:euphoria/rev/f0d5139561af

changeset: 6133:f0d5139561af user: Jason Gade <jaygade@yahoo.com> date: Thu Jul 11 05:47:24 2013 -0700 files: source/compile.e description: ticket:874, fixed some casting problems in compile.e probably introduced in the previous change.

5. Comment by jaygade Jul 11, 2013

See: hg:euphoria/rev/991791b126ad

changeset: 6134:991791b126ad tag: tip user: Jason Gade <jaygade@yahoo.com> date: Thu Jul 11 17:24:02 2013 -0700 files: include/euphoria.h source/compile.e description: More changes to casts between object<->double ticket:874

Search



Quick Links

User menu

Not signed in.

Misc Menu