[GHC] #16302: A non-function coerced to a function can cause a stg_ap_pp_ret

GHC ghc-devs at haskell.org
Mon Feb 11 04:35:02 UTC 2019


#16302: A non-function coerced to a function can cause a stg_ap_pp_ret
-------------------------------------+-------------------------------------
           Reporter:  WheatWizard    |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.4.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:  x86_64         |   Type of failure:  Runtime crash
  (amd64)                            |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 If you create an function by unsafe coercing a non-function you can get
 some strange functions.  If you then take one of these function and apply
 it something it crashes with a {{{stg_ap_pp_ret}}}.  Here is a pretty
 minimal example.

 {{{
 import Unsafe.Coerce
 main=(unsafeCoerce()::a->IO())1
 }}}

 You can reproduce it online here:
 https://tio.run/##y0gszk7Nyfn/PzO3IL@oRCE0rzgxLVXPOT@1KDmVKzcxM89WoxQsBhHS0LSyStS18/TX0NQ0/P8fAA

 Here is another one:

 {{{
 import Unsafe.Coerce
 g=unsafeCoerce()::a->a
 main=print$g(g)1
 }}}

 If you coerce functions this doesn't appear to happen.

 For example:

 {{{
 import Unsafe.Coerce
 main=(unsafeCoerce id::a->IO())1
 }}}

 is a fine program.  Sometimes this causes a segmentation fault
 (particularly with higher airity functions):

 {{{
 import Unsafe.Coerce
 main=(unsafeCoerce(+)::a->IO())1
 }}}

 but I've never gotten it to make a {{{stg_ap_pp_ret}}}.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16302>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list