Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,259
    • Issues 5,259
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 565
    • Merge requests 565
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19345
Closed
Open
Issue created Feb 10, 2021 by sheaf@sheafMaintainer

Optimisations cause incorrect runtime result in Integer calculation

Summary

The following program

module Main where

import Numeric.Natural
  ( Natural )

a, q :: Natural
a = fromIntegral ( 18446744073709551616 :: Integer )
q = 18446744073709551616

main :: IO ()
main = print ( fromIntegral ( a `div` q ) :: Word )

runs into the following strange behaviour:

GHC 8.10 -O0

> main
1

GHC 8.10 -O1

> main
1

GHC 9.0 -O0

> main
1

GHC 9.0 -O1

> main
0

Tagging @hsyl20 as I expect him to know about what's going on.

Steps to reproduce

Simply run the above program with either ghc -O0 or ghc -O1 to get the different results.

Further remarks

Changing fromIntegral to fromInteger causes GHC 9.0 with optimisations to return the correct result, so it might be an incorrect rewrite rule involving fromIntegral?

Environment

On GHC 9.0.1, Windows 10 x64.

Edited Feb 11, 2021 by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking