Skip to content

Word.toInt does not raise an exception when out of range #340

Description

@Skyb0rg007

Version

110.99.7.1 (Latest)

Operating System

  • Any
  • Linux
  • macOS
  • Windows
  • Other Unix

OS Version

Ubuntu on Windows 11 WSL

Processor

  • Any
  • Arm (using Rosetta)
  • PowerPC
  • Sparc
  • x86 (32-bit)
  • x86-64 (64-bit)
  • Other

System Component

Basis Library

Severity

Minor

Description

Word.toInt produces values outside the range [0,2^(wordSize-1))

Transcript

- Word.toInt ~1;
val it = 0wx7FFFFFFFFFFFFFFF : word
- Word.fromInt ~1 = 0wx7FFFFFFFFFFFFFFF;
val it = false : bool

Expected Behavior

- Word.toInt ~1;
val it = 0wx7FFFFFFFFFFFFFFF : word
- Word.fromInt ~1 = 0wx7FFFFFFFFFFFFFFF;
val it = true : bool

Steps to Reproduce

Type the above code

Additional Information

I believe this is an issue in conversion: (W63)9223372036854775807 is converted to (I63t)9223372036854775807 when it should be converted to (I63t)~1.

[After fcontract+eta ...]

v5{1} : (FCT)  =
  FN([v11{0} : ???],
    v1{2} = PRIMOP(copy_63_63, <I63> -f-> <I63>, []) [(I63)~1]
    [v3{1}] = IF PRIMOP(=u63, <I63,I63> -f-> <VOID>, []) [v1,(W63)9223372036854775807]
               THEN
                   v8{1} = WRAP(I63, (I63)1)
                   RETURN [v8]
               ELSE
                   v10{1} = WRAP(I63, (I63)0)
                   RETURN [v10]
    v6{1} = STRUCT [v3,v1,(W63)9223372036854775807]
    RETURN [v6])


[After convert ...]

std v5(v13[C],v11[PR0]) =
   v17(v18[PV]) =
      v17("bogus")
   v12(v19[PV]) =
      v17("bogus")
   copy_63_63((I63t)~1) -> v1[I]
   v15(v14[PV]) =
      {v14,v1,(I63t)9223372036854775807} -> v6
      v13(v6)
   if u63=(v1,(I63t)9223372036854775807) [v16] then
      wrap_i63((I63t)1) -> v8[PV]
      v15(v8)
   else
      wrap_i63((I63t)0) -> v10[PV]
      v15(v10)


Email address

ssoss AT uchicago DOT edu

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompilerproblem with compilerfixed-in-110.99.8Issues fixed in the 110.99.8 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions