[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: Fix rewriting invalid shifts to errors

Marge Bot gitlab at gitlab.haskell.org
Sun Jun 2 21:54:41 UTC 2019



 Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
1503da32 by Ömer Sinan Ağacan at 2019-06-01T15:18:57Z
Fix rewriting invalid shifts to errors

Fixes #16449.

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. 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.

- - - - -
2e297b36 by Ömer Sinan Ağacan at 2019-06-01T15:19:35Z
rts: Remove unused decls from CNF.h

- - - - -
f6fe90d3 by Takenobu Tani at 2019-06-02T21:54:36Z
Add `-haddock` option under ci condition to fix #16415

In order to use the `:doc` command in ghci, it is necessary
to compile for core libraries with `-haddock` option.

Especially, the `-haddock` option is essential for release building.

Note:
  * The `-haddock` option may affect compile time and binary size.
  * But hadrian has already set `-haddock` as the default.
  * This patch affects the make-based building.

This patch has been split from !532.

- - - - -
8f8c0eb8 by Takenobu Tani at 2019-06-02T21:54:36Z
Add `-haddock` to perf.mk rather than prepare-system.sh

To cover ci conditions from ghc8.6 to 8.9, I add `-haddock` option
to `mk/flavours/perf.mk` rather than `.circleci/prepare-system.sh`.

Because in windows condition of ghc-8.9, `mk/flavours/*` is included
after `prepare-system.sh`.

In addition, in linux condition of ghc-8.6, `mk/flavors/perf.mk` is used.

- - - - -
805fc5f8 by Takenobu Tani at 2019-06-02T21:54:36Z
Add `-haddock` to prepare-system.sh and .gitlab-ci.yml

To cover ci conditions from ghc8.6 to 8.9, I add `-haddock` option
to `.circleci/prepare-system.sh` and .gitlab-ci.yml.
after including `mk/flavours/*`.

- - - - -
788c8723 by Ben Gamari at 2019-06-02T21:54:36Z
gitlab-ci: Use GHC 8.6.5 for Windows CI builds

- - - - -


9 changed files:

- .circleci/prepare-system.sh
- .gitlab-ci.yml
- compiler/prelude/PrelRules.hs
- rts/sm/CNF.h
- + testsuite/tests/codeGen/should_compile/T16449_1.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_run/T16449_2.hs
- + testsuite/tests/codeGen/should_run/T16449_2.stderr
- testsuite/tests/codeGen/should_run/all.T


Changes:

=====================================
.circleci/prepare-system.sh
=====================================
@@ -30,6 +30,7 @@ BuildFlavour=$BUILD_FLAVOUR
 ifneq "\$(BuildFlavour)" ""
 include mk/flavours/\$(BuildFlavour).mk
 endif
+GhcLibHcOpts+=-haddock
 EOF
 
 case "$(uname)" in


=====================================
.gitlab-ci.yml
=====================================
@@ -552,14 +552,14 @@ validate-x86_64-linux-fedora27:
   cache:
     paths:
       - cabal-cache
-      - ghc-8.6.2
+      - ghc-8.6.5
       - ghc-tarballs
 
 .build-windows-hadrian:
   extends: .build-windows
   stage: full-build
   variables:
-    GHC_VERSION: "8.6.2"
+    GHC_VERSION: "8.6.5"
   # due to #16574 this currently fails
   allow_failure: true
   script:
@@ -601,13 +601,14 @@ nightly-i386-windows-hadrian:
   allow_failure: true
   variables:
     BUILD_FLAVOUR: "quick"
-    GHC_VERSION: "8.6.2"
+    GHC_VERSION: "8.6.5"
     BIN_DIST_PREP_TAR_COMP: "bindistprep/ghc-x86_64-mingw32.tar.xz"
   script:
     - |
       python boot
       bash -c './configure --enable-tarballs-autodownload GHC=`pwd`/toolchain/bin/ghc HAPPY=`pwd`/toolchain/bin/happy ALEX=`pwd`/toolchain/bin/alex $CONFIGURE_ARGS'
     - bash -c "echo include mk/flavours/${BUILD_FLAVOUR}.mk > mk/build.mk"
+    - bash -c "echo 'GhcLibHcOpts+=-haddock' >> mk/build.mk"
     - bash -c "PATH=`pwd`/toolchain/bin:$PATH make -j`mk/detect-cpu-count.sh`"
     - bash -c "PATH=`pwd`/toolchain/bin:$PATH make binary-dist TAR_COMP_OPTS=-1"
     - bash -c 'make V=0 test THREADS=`mk/detect-cpu-count.sh` JUNIT_FILE=../../junit.xml'


=====================================
compiler/prelude/PrelRules.hs
=====================================
@@ -467,13 +467,16 @@ shiftRule :: (DynFlags -> Integer -> Int -> Integer) -> RuleM CoreExpr
 -- Used for shift primops
 --    ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word#
 --    SllOp, SrlOp           :: Word# -> Int# -> Word#
--- See Note [Guarding against silly shifts]
 shiftRule shift_op
   = do { dflags <- getDynFlags
        ; [e1, Lit (LitNumber LitNumInt shift_len _)] <- getArgs
        ; case e1 of
            _ | shift_len == 0
              -> return e1
+             -- See Note [Guarding against silly shifts]
+             | shift_len < 0 || shift_len > wordSizeInBits dflags
+             -> return $ mkRuntimeErrorApp rUNTIME_ERROR_ID wordPrimTy
+                           ("Bad shift length " ++ show shift_len)
 
            -- Do the shift at type Integer, but shift length is Int
            Lit (LitNumber nt x t)


=====================================
rts/sm/CNF.h
=====================================
@@ -15,9 +15,6 @@
 
 #include "BeginPrivate.h"
 
-void              initCompact  (void);
-void              exitCompact  (void);
-
 StgCompactNFData *compactNew   (Capability      *cap,
                                 StgWord          size);
 void              compactResize(Capability       *cap,


=====================================
testsuite/tests/codeGen/should_compile/T16449_1.hs
=====================================
@@ -0,0 +1,8 @@
+module T16449_1 where
+
+import Data.Bits (setBit)
+
+f :: Int
+f = foldl setter 0 $ zip [0..] [()]
+  where
+    setter v (ix, _) = setBit v ix


=====================================
testsuite/tests/codeGen/should_compile/all.T
=====================================
@@ -59,3 +59,5 @@ test('T15155',
 
 test('T15155l', when(unregisterised(), skip),
      makefile_test, [])
+
+test('T16449_1', normal, compile, [''])


=====================================
testsuite/tests/codeGen/should_run/T16449_2.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE MagicHash #-}
+
+module Main where
+
+import GHC.Prim
+import GHC.Int
+
+-- Shift should be larger than the word size (e.g. 64 on 64-bit) for this test.
+main = print (I# (uncheckedIShiftL# 1# 1000#))


=====================================
testsuite/tests/codeGen/should_run/T16449_2.stderr
=====================================
@@ -0,0 +1 @@
+T16449_2: Bad shift length 1000


=====================================
testsuite/tests/codeGen/should_run/all.T
=====================================
@@ -195,3 +195,4 @@ test('T15892',
         extra_run_opts('+RTS -G1 -A32k -RTS') ],
      compile_and_run, ['-O'])
 test('T16617', normal, compile_and_run, [''])
+test('T16449_2', exit_code(1), compile_and_run, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/26736f3c71df568f5fb71e2fb25d2534efb94759...788c8723fbee7e0e8a451ff0cab1b7ca434830e8

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/26736f3c71df568f5fb71e2fb25d2534efb94759...788c8723fbee7e0e8a451ff0cab1b7ca434830e8
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190602/162d49e0/attachment-0001.html>


More information about the ghc-commits mailing list