summaryrefslogtreecommitdiff
path: root/compiler/deSugar
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2017-10-16 19:02:01 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2017-10-16 19:03:11 +0200
commitadd85cc2a3ec0bda810dca2a35264308ffaab069 (patch)
tree13e46f3397433eaa689e58737a928db659c23010 /compiler/deSugar
parent6aa6a86b836efaabcb471894d0b549a2e56703e6 (diff)
downloadhaskell-add85cc2a3ec0bda810dca2a35264308ffaab069.tar.gz
Fix panic for `ByteArray#` arguments in CApiFFI foreign imports
Declarations such as foreign import capi unsafe "string.h strlen" c_strlen_capi :: ByteArray# -> IO CSize foreign import capi unsafe "string.h memset" c_memset_capi :: MutableByteArray# s -> CInt -> CSize -> IO () would cause GHC to panic because the CApiFFI c-wrapper generator didn't know what C type to use for `(Mutable)ByteArray#` types (unlike the `ccall` codepath). This addresses #9274 Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D4092
Diffstat (limited to 'compiler/deSugar')
-rw-r--r--compiler/deSugar/DsForeign.hs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/deSugar/DsForeign.hs b/compiler/deSugar/DsForeign.hs
index 01173c932d..492d353cc0 100644
--- a/compiler/deSugar/DsForeign.hs
+++ b/compiler/deSugar/DsForeign.hs
@@ -717,6 +717,12 @@ toCType = f False
-- through one layer of type synonym etc.
| Just t' <- coreView t
= f voidOK t'
+ -- This may be an 'UnliftedFFITypes'-style ByteArray# argument
+ -- (which is marshalled like a Ptr)
+ | Just byteArrayPrimTyCon == tyConAppTyConPicky_maybe t
+ = (Nothing, text "const void*")
+ | Just mutableByteArrayPrimTyCon == tyConAppTyConPicky_maybe t
+ = (Nothing, text "void*")
-- Otherwise we don't know the C type. If we are allowing
-- void then return that; otherwise something has gone wrong.
| voidOK = (Nothing, text "void")