[comp.lang.icon] Bignum bug in Icon Version 8

tim@ksr.com (Tim Peters) (04/07/91)

Attempting to add the most negative native integer to a bignum causes an
"Illegal instruction" trap on our SPARC (Solbourne, pretty much
equivalent to a Sun-4) installation of Icon V8.

Following is a terminal session showing the problem:

kaos 338= cat bug.icn
procedure main()
   local i, j
   write( "host: ", &host )
   write( "version: ", &version )
   write( "features:" )
   every write( "   ", &features )

   i := -2147483647
   i -:= 1
   j := 6103515625
   write(i," ",j)
   i +:= j
end
kaos 339= /usr/local/lib/icon/v8/bin/icont -u bug -x
Translating:
bug.icn:
  main (521/15000)
No errors
Linking:
Executing:
host: kaos
version: Icon Version 8.0.  May 7, 1990
features:
   UNIX
   ASCII
   co-expressions
   direct execution
   environment variables
   error trace back
   executable images
   expandable regions
   external functions
   large integers
   math functions
   memory monitoring
   pipes
   string invocation
   system function
-2147483648 6103515625
Illegal instruction
kaos 340= echo $?
132
kaos 341= 

There's a longish (perhaps a second) pause between the output of i & j
and the "Illegal instruction" trap, leading me to believe that Icon has
gotten horribly confused.

Note that i is -2^31, the most negative native integer on this "long
ints are 4 bytes" machine.  The problem does not occur for other values
of i (well, I didn't try *all* possible values ... <grin>), and goes
away if i is intialized via

  i := -2147483648

instead.  Indeed, *most* plausible ways of setting i to -2^31 make the
problem go away:  I assume the code sequence in the test case is special
only in that it causes i to "look like" a native integer internally,
while most other ways cause i to look like a bignum internally.

Finally, I doubt this is a local installation problem, because I've used
Icon's bignums extensively over several months, and this is the first
major error I've stumbled into.

If I can be of any further assistance in tracking this down, please let
me know.

one-of-icon's-admirers-ly y'rs  - tim

Tim Peters   Kendall Square Research Corp
tim@ksr.com,  ksr!tim@harvard.harvard.edu