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,250
    • Issues 5,250
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 576
    • Merge requests 576
  • 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
  • #19917
Closed
Open
Issue created May 30, 2021 by Andreas Abel@abel

Unsound optimization with `error`, introduced in GHC 8.2

We discovered an unsound optimization (see https://github.com/agda/agda-stdlib/pull/1512) in GHC starting with 8.2. I managed to shrink it down to the following code:

-- Unsound compiler optimization in presence of @error@.

foo :: String -> String
foo d1@(_:_)
  | not (all (== '-') d1)
  , last d1 == '\r'
  = error "OK1"
foo _ = error "OK2"

main = putStr $ foo "Hello, world!"

With -O0, or until GHC 8.0.2, this outputs

    <main>: OK2
    CallStack (from HasCallStack):
      error, called at <loc> in main:Main

With -O1 or -O2 and GHC 8.2 - 9.0.1, (I tested from 8.2.2), this gives:

    Prelude.last: empty list
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking