[GHC] #14624: HEAD panic in ghc:DsForeign: toCType

#14624: HEAD panic in ghc:DsForeign: toCType -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Linux Architecture: x86_64 | Type of failure: Compile-time (amd64) | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The following program crashes in 8.2.2 and HEAD (8.5.20171228). {{{#!hs {-# LANGUAGE ForeignFunctionInterface, CApiFFI, GHCForeignImportPrim, QuasiQuotes, TemplateHaskell, JavaScriptFFI, MagicHash, UnliftedFFITypes #-} module TH_foreignCallingConventions where import GHC.Prim import Control.Applicative import Language.Haskell.TH import System.IO import Foreign.Ptr $( do let fi cconv safety lbl name ty = ForeignD (ImportF cconv safety lbl name ty) dec1 <- fi CCall Interruptible "&" (mkName "foo") <$> [t| Ptr () |] dec2 <- fi CApi Safe "bar" (mkName "bar") <$> [t| Int# -> Int# |] -- the declarations below would result in warnings or errors when returned dec3 <- fi CApi Unsafe "baz" (mkName "baz") <$> [t| Double -> IO () |] dec4 <- fi StdCall Safe "bay" (mkName "bay") <$> [t| (Int -> Bool) -> IO Int |] dec5 <- fi JavaScript Unsafe "bax" (mkName "bax") <$> [t| Ptr Int -> IO String |] runIO $ mapM_ (putStrLn . pprint) [dec1, dec2, dec3, dec4, dec5] >> hFlush stdout return [dec1, dec2] ) }}} This program is derived by mutating test TH_foreignCallingConventions.hs. {{{#!diff diff --git a/testsuite/tests/th/TH_foreignCallingConventions.hs b/testsuite/tests/th/TH_foreignCallingConventions.hs index ee39510..16789af 100644 --- a/testsuite/tests/th/TH_foreignCallingConventions.hs +++ b/testsuite/tests/th/TH_foreignCallingConventions.hs @@ -13,7 +13,7 @@ import Foreign.Ptr $( do let fi cconv safety lbl name ty = ForeignD (ImportF cconv safety lbl name ty) dec1 <- fi CCall Interruptible "&" (mkName "foo") <$> [t| Ptr () |] - dec2 <- fi Prim Safe "bar" (mkName "bar") <$> [t| Int# -> Int# |] + dec2 <- fi CApi Safe "bar" (mkName "bar") <$> [t| Int# -> Int# |] -- the declarations below would result in warnings or errors when returned dec3 <- fi CApi Unsafe "baz" (mkName "baz") <$> [t| Double -> IO () |] dec4 <- fi StdCall Safe "bay" (mkName "bay") <$> [t| (Int -> Bool) -> IO Int |] }}} Log: {{{ foreign import capi safe "bar" bar :: GHC.Prim.Int# -> GHC.Prim.Int# foreign import capi unsafe "baz" baz :: GHC.Types.Double -> GHC.Types.IO () foreign import stdcall safe "bay" bay :: (GHC.Types.Int -> GHC.Types.Bool) -> GHC.Types.IO GHC.Types.Int foreign import javascript unsafe "bax" bax :: GHC.Ptr.Ptr GHC.Types.Int -> GHC.Types.IO GHC.Base.String ghc: panic! (the 'impossible' happened) (GHC version 8.5.20171228 for x86_64-unknown-linux): toCType Int# Call stack: CallStack (from HasCallStack): callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable pprPanic, called at compiler/deSugar/DsForeign.hs:730:17 in ghc:DsForeign Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: HEAD panic in ghc:DsForeign: toCType -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by tianxiaogu): * Attachment "crash-ghc-TH_foreignCallingConventions.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: HEAD panic in ghc:DsForeign: toCType -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): A simpler way to trigger the panic that doesn't involve any Template Haskell: {{{#!hs {-# LANGUAGE CApiFFI #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnliftedFFITypes #-} module Foo where import GHC.Exts (Int#) foreign import capi safe "bar" bar :: Int# -> Int# }}} {{{ $ /opt/ghc/8.2.2/bin/ghc Foo.hs [1 of 1] Compiling Foo ( Foo.hs, Foo.o ) ghc: panic! (the 'impossible' happened) (GHC version 8.2.2 for x86_64-unknown-linux): toCType Int# Call stack: CallStack (from HasCallStack): prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable pprPanic, called at compiler/deSugar/DsForeign.hs:726:17 in ghc:DsForeign }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: HEAD panic in ghc:DsForeign: toCType -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: hvr (added) Comment: That being said, I'm not terribly familiar with what requirements the `capi` calling convention imposes on its argument and result types. Is there a specification for this somewhere? All I found was [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi- chap.html?highlight=capiffi#the-capi-calling-convention this terse section] of the users' guide on `CApiFFI`, which doesn't formalize what types are accepted, much less what should happen if an //incorrect// type is provided, as what appears to be happening here. cc'ing hvr, who might have some thoughts on this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: HEAD panic in ghc:DsForeign: toCType -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * os: Linux => Unknown/Multiple * component: Compiler => Compiler (FFI) * architecture: x86_64 (amd64) => Unknown/Multiple -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: capi panic (toCType Int#) -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14624: capi panic (toCType Int#) -------------------------------------+------------------------------------- Reporter: tianxiaogu | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #9274 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by hvr): * related: => #9274 Comment: Oh dear, this is another instance of #9274 (see add85cc2a3ec0bda810dca2a35264308ffaab069 for a hint on how to fix this instance here). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14624#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC