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,346
    • Issues 5,346
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 567
    • Merge requests 567
  • 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
  • Merge requests
  • !1021

Fix rewriting invalid shifts to errors

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Ömer Sinan Ağacan requested to merge osa1/ghc:fix_16449 into master May 24, 2019
  • Overview 11
  • Commits 1
  • Pipelines 2
  • Changes 6

Fixes #16449 (closed).

5341edf3 removed a code in rewrite rules for bit shifts, which broke the "silly shift guard", causing generating invalid bit shifts or heap overflow in compile time while trying to evaluate those invalid bit shifts.

The "guard" is explained in Note [Guarding against silly shifts] in PrelRules.hs.

More specifically, this was the breaking change:

--- a/compiler/prelude/PrelRules.hs
+++ b/compiler/prelude/PrelRules.hs
@@ -474,12 +474,11 @@ shiftRule shift_op
        ; case e1 of
            _ | shift_len == 0
              -> return e1
-             | shift_len < 0 || wordSizeInBits dflags < shift_len
-             -> return (mkRuntimeErrorApp rUNTIME_ERROR_ID wordPrimTy
-                                        ("Bad shift length" ++ show shift_len))

This patch reverts this change.

Two new tests added:

  • T16449_1: The original reproducer in #16449 (closed). This was previously casing a heap overflow in compile time when CmmOpt tries to evaluate the large (invalid) bit shift in compile time, using Integer as the result type. Now it builds as expected. We now generate an error for the shift as expected.

  • T16449_2: Tests code generator for large (invalid) bit shifts.

Edited May 24, 2019 by Ömer Sinan Ağacan
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: fix_16449