Literal overflow test fails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Literal overflow test fails

Simon Peyton Jones
On 32 bit Windows I get this (with HEAD).

libraries\Win32\Graphics\Win32\GDI\HDC.hs:145:14: Warning:
    Literal 2147483648 of type Int overflows

The offending code is:

setTextCharacterExtra dc extra =
  failIf (== 0x80000000) "SetTextCharacterExtra" $
    c_SetTextCharacterExtra dc extra

The new literal-overflow test objects to 0x80000000 :: Int.  I'm not sure if it should object; in this case we are deliberately using the bit-pattern for minBound.

Also what happens on a 64-bit architecture?

What should the behaviour here be?

- should we use minBound here?
- what should the new literal-overlflow code do for 0xblah constants?

This is currently breaking the HEAD build.

Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130803/25b6faa4/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

Literal overflow test fails

Carter Schonwald
Hey Simon

heres some info about whats happening, and it may point out whats different

http://stackoverflow.com/questions/384502/what-is-the-bit-size-of-long-on-64-bit-windows
namely: pointers on 64bit windows are 64bit, but c ints are 32bit

hope that helps!


On Sat, Aug 3, 2013 at 5:47 PM, Simon Peyton-Jones <simonpj at microsoft.com>wrote:

>  On 32 bit Windows I get this (with HEAD).****
>
> ** **
>
> libraries\Win32\Graphics\Win32\GDI\HDC.hs:145:14: Warning:****
>
>     Literal 2147483648 of type Int overflows****
>
> ** **
>
> The offending code is:****
>
> ** **
>
> setTextCharacterExtra dc extra =****
>
>   failIf (== 0x80000000) "SetTextCharacterExtra" $****
>
>     c_SetTextCharacterExtra dc extra****
>
> ** **
>
> The new literal-overflow test objects to 0x80000000 :: Int.  I?m not sure
> if it should object; in this case we are deliberately using the bit-pattern
> for minBound.****
>
> ** **
>
> Also what happens on a 64-bit architecture?****
>
> ** **
>
> What should the behaviour here be?   ****
>
> ** **
>
> - should we use minBound here?****
>
> - what should the new literal-overlflow code do for 0xblah constants?****
>
> ** **
>
> This is currently breaking the HEAD build.****
>
> ** **
>
> Simon****
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130803/b7851125/attachment.htm>

Reply | Threaded
Open this post in threaded view
|

Literal overflow test fails

Ian Lynagh
In reply to this post by Simon Peyton Jones
On Sat, Aug 03, 2013 at 09:47:07PM +0000, Simon Peyton-Jones wrote:

>
> libraries\Win32\Graphics\Win32\GDI\HDC.hs:145:14: Warning:
>     Literal 2147483648 of type Int overflows
>
> The offending code is:
>
> setTextCharacterExtra dc extra =
>   failIf (== 0x80000000) "SetTextCharacterExtra" $
>     c_SetTextCharacterExtra dc extra
>
> - should we use minBound here?

The spec defines the failure value as 0x80000000, so it would be better
to use that constant:
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd145092%28v=vs.85%29.aspx

I had a similar problem with a 0xdeadbeef constant in the compiler
source. I changed it to be
    fromIntegral (0xdeadbeef :: Word32)
instead. I'd suggest doing similarly for the 0x80000000.

> - what should the new literal-overlflow code do for 0xblah constants?

In my opinion, it's doing the right thing.


Thanks
Ian




Reply | Threaded
Open this post in threaded view
|

FW: Literal overflow test fails

Simon Peyton Jones
Austin

Could you act on this thread please?  Currently I think the Windows build is broken because of it.

I think Ian is right, namely that the way to get a particular bit-pattern with type 'Int' is to use fromIntegral.  But it needs a comment to explain the idiom.

eg try compiling this with -O:

import Data.Int
import Data.Word

foo :: Int32
foo = fromIntegral (0x80000000 :: Word32) :: Int32

You get

Foo.foo = GHC.Int.I32# (-2147483648)


-----Original Message-----
From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Ian Lynagh
Sent: 05 August 2013 16:34
To: ghc-devs at haskell.org
Subject: Re: Literal overflow test fails

On Sat, Aug 03, 2013 at 09:47:07PM +0000, Simon Peyton-Jones wrote:

>
> libraries\Win32\Graphics\Win32\GDI\HDC.hs:145:14: Warning:
>     Literal 2147483648 of type Int overflows
>
> The offending code is:
>
> setTextCharacterExtra dc extra =
>   failIf (== 0x80000000) "SetTextCharacterExtra" $
>     c_SetTextCharacterExtra dc extra
>
> - should we use minBound here?

The spec defines the failure value as 0x80000000, so it would be better
to use that constant:
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd145092%28v=vs.85%29.aspx

I had a similar problem with a 0xdeadbeef constant in the compiler
source. I changed it to be
    fromIntegral (0xdeadbeef :: Word32)
instead. I'd suggest doing similarly for the 0x80000000.

> - what should the new literal-overlflow code do for 0xblah constants?

In my opinion, it's doing the right thing.


Thanks
Ian


_______________________________________________
ghc-devs mailing list
ghc-devs at haskell.org
http://www.haskell.org/mailman/listinfo/ghc-devs




Reply | Threaded
Open this post in threaded view
|

FW: Literal overflow test fails

Austin Seipp-4
Yes, this slipped by my radar.

I've got my win8 build machine up now, so I can push something shortly.

On Mon, Aug 19, 2013 at 3:40 AM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:

> Austin
>
> Could you act on this thread please?  Currently I think the Windows build is broken because of it.
>
> I think Ian is right, namely that the way to get a particular bit-pattern with type 'Int' is to use fromIntegral.  But it needs a comment to explain the idiom.
>
> eg try compiling this with -O:
>
> import Data.Int
> import Data.Word
>
> foo :: Int32
> foo = fromIntegral (0x80000000 :: Word32) :: Int32
>
> You get
>
> Foo.foo = GHC.Int.I32# (-2147483648)
>
>
> -----Original Message-----
> From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf Of Ian Lynagh
> Sent: 05 August 2013 16:34
> To: ghc-devs at haskell.org
> Subject: Re: Literal overflow test fails
>
> On Sat, Aug 03, 2013 at 09:47:07PM +0000, Simon Peyton-Jones wrote:
>>
>> libraries\Win32\Graphics\Win32\GDI\HDC.hs:145:14: Warning:
>>     Literal 2147483648 of type Int overflows
>>
>> The offending code is:
>>
>> setTextCharacterExtra dc extra =
>>   failIf (== 0x80000000) "SetTextCharacterExtra" $
>>     c_SetTextCharacterExtra dc extra
>>
>> - should we use minBound here?
>
> The spec defines the failure value as 0x80000000, so it would be better
> to use that constant:
>     http://msdn.microsoft.com/en-us/library/windows/desktop/dd145092%28v=vs.85%29.aspx
>
> I had a similar problem with a 0xdeadbeef constant in the compiler
> source. I changed it to be
>     fromIntegral (0xdeadbeef :: Word32)
> instead. I'd suggest doing similarly for the 0x80000000.
>
>> - what should the new literal-overlflow code do for 0xblah constants?
>
> In my opinion, it's doing the right thing.
>
>
> Thanks
> Ian
>
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>



--
Regards,
Austin - PGP: 4096R/0x91384671