
#15262: TH splice containing numeric literal 0 causes heap overflow while cross- compiling -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.5 Keywords: | Operating System: MacOS X Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Tested off commit `9976bed24dda9449ac2e3e95fb4bf8b379114a28`, running on macOS 10.13.5, trying to compile for iOS. 1. Compile a GHC that cross compiles to `x86_64-apple-ios` (i.e. with `./configure --build=x86_64-apple-darwin --host=x86_64-apple-darwin --target=x86_64-apple-ios; make`). 2. Compile a `ghc-iserv` that can run on the build system (i.e. with `./configure; cd utils/iserv; make`) 3. Try to cross-compile the following file (i.e `x86_64-apple-ios-ghc -fexternal-interpreter -pgmi=path/to/ghc-iserv T.hs`): {{{#!hs {-# LANGUAGE TemplateHaskell #-} module T where $([d| zero = 0 |]) }}} Expected: Compiles fine. Actual: {{{ [1 of 1] Compiling T ( T.hs, T.o ) T.hs:1:1: error: Exception when trying to run compile-time code: heap overflow Code: [d| zero = 0 |] | 1 | {-# LANGUAGE TemplateHaskell #-} | ^ }}} For more fun: * This problem appears to only affect the numeric literal `0`. * `0.0` is not fine. * `1` is fine. * `1 - 1` appears to be a workaround. * `0.1` is fine. * "Burying" the `0` inside another expression is not fine (e.g. `zero = [0]`). * I can even compile most of `singletons`, and it only chokes when the `0` literal first appears (`negate x = 0 - x`). * The `0` has to actually appear in the result. (`$(const [d| |] [d| zero = 0 |])` is fine.) * `0#` is not fine. * This problem only appears when cross-compiling. If I complete the build of the native GHC above and use it instead of the cross-compiler but still use `-fexternal-interpreter`, everything is fine. * Moving the declaration outside of the TH brackets is fine. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler