Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of range literals #1

Open
dmjio opened this issue Nov 29, 2016 · 1 comment
Open

Out of range literals #1

dmjio opened this issue Nov 29, 2016 · 1 comment

Comments

@dmjio
Copy link

dmjio commented Nov 29, 2016

@atomb,

cc @travitch

When attempting to build, I noticed this warning in cabal,

src/Dalvik/Instruction.hs:642:46: Warning:
    Literal 240 is out of the Int8 range -128..127

src/Dalvik/Instruction.hs:646:50: Warning:
    Literal 4294901760 is out of the Int32 range -2147483648..2147483647

src/Dalvik/Instruction.hs:651:42: Warning:
    Literal 18446744069414584320 is out of the Int64 range -9223372036854775808..9223372036854775807

regarding these lines:

signExt4 :: Word8 -> Int8
signExt4 w = w' .|. (if w' .&. 0x8 /= 0 then 0xF0 {- 240 -} else 0)
  where w' = fromIntegral w

signExt16 :: Word32 -> Int32
signExt16 w = w' .|. (if w' .&. 0x8000 /= 0 then 0xFFFF0000 {-4294901760-} else 0)
  where w' = fromIntegral w

signExt32 :: Int64 -> Int64
signExt32 w =
  w' .|. (if w' .&. 0x80000000 /= 0 then 0xFFFFFFFF00000000 {-18446744069414584320-} else 0)
    where w' = fromIntegral w

Is the intention here to make the these literals max bounds?

@travitch
Copy link
Collaborator

The intent is for those literals to be unsigned values, but GHC is interpreting them as signed (it gets the right bit patterns, but issues the warning). Putting type annotations directly on them might work, but I'm not sure due to the desugaring of literals with fromIntegral. I will give that a shot sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants