#1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C
--------------------------+-------------------------------------------------
 Reporter:  Isaac Dupree  |          Owner:            
     Type:  bug           |         Status:  new       
 Priority:  normal        |      Milestone:  6.8 branch
Component:  Compiler      |        Version:  6.8.1     
 Severity:  normal        |     Resolution:            
 Keywords:                |     Difficulty:  Unknown   
 Testcase:  numeric/1603  |   Architecture:  Multiple  
       Os:  Multiple      |  
--------------------------+-------------------------------------------------
Changes (by simonmar):

  * testcase:  => numeric/1603
  * version:  6.6.1 => 6.8.1
  * os:  Linux => Multiple
  * architecture:  x86 => Multiple
  * milestone:  6.8.2 => 6.8 branch

Comment:

 gcc is being too clever.  It is assuming that because the first argument
 to % is the result of converting an unsigned to a signed integer, that its
 value is therefore non-negative, and uses this knowledge to optimise the
 code it generates for 'x % 0x40000000'.  I believe gcc is entitled to make
 this optimisation, because arithmetic in C is only defined within the
 bounds of the types, and that includes type conversions.  Unfortunately
 the `-fwrapv` option doesn't apply to type conversions, apparently.

 I don't see an easy fix (but suggestions are welcome).  We use unsigned
 types everywhere in our back end, only converting to signed types in order
 to perform signed operations.  This strategy apparently relies on
 undefined C behaviour.

 I've added a test (will be pushed shortly).

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1603#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to