diff options
author | Sylvain HENRY <hsyl20@gmail.com> | 2015-11-11 12:32:08 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-11-11 12:32:16 +0100 |
commit | badf5d54907a5a5e9224c44310f991a52379b4c1 (patch) | |
tree | 94f4b585569ba424a1b6733797262325b3ab8bdc /compiler/ghci | |
parent | 0f49508399a1fc145e17950ea1591da7f0de4f2a (diff) | |
download | haskell-badf5d54907a5a5e9224c44310f991a52379b4c1.tar.gz |
Detect invalid foreign imports in bytecode compiler
The bytecode compiler doesn't handle every foreign import calling
convention. Instead of crashing during the generation of the foreign
call, we display an error.
Fix lint warnings
Test Plan: prog014 ghci test added
Reviewers: austin, hvr, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1458
GHC Trac Issues: #10462
Diffstat (limited to 'compiler/ghci')
-rw-r--r-- | compiler/ghci/ByteCodeGen.hs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/compiler/ghci/ByteCodeGen.hs b/compiler/ghci/ByteCodeGen.hs index b06d1a4b3f..11a8c6d098 100644 --- a/compiler/ghci/ByteCodeGen.hs +++ b/compiler/ghci/ByteCodeGen.hs @@ -598,7 +598,10 @@ schemeT d s p app -- Case 1 | Just (CCall ccall_spec) <- isFCallId_maybe fn - = generateCCall d s p ccall_spec fn args_r_to_l + = if isSupportedCConv ccall_spec + then generateCCall d s p ccall_spec fn args_r_to_l + else unsupportedCConvException + -- Case 2: Constructor application | Just con <- maybe_saturated_dcon, @@ -1508,13 +1511,25 @@ bcIdUnaryType x = case repType (idType x) of -- See bug #1257 unboxedTupleException :: a -unboxedTupleException - = throwGhcException - (ProgramError - ("Error: bytecode compiler can't handle unboxed tuples.\n"++ - " Possibly due to foreign import/export decls in source.\n"++ - " Workaround: use -fobject-code, or compile this module to .o separately.")) - +unboxedTupleException = throwGhcException (ProgramError + ("Error: bytecode compiler can't handle unboxed tuples.\n"++ + " Possibly due to foreign import/export decls in source.\n"++ + " Workaround: use -fobject-code, or compile this module to .o separately.")) + +-- | Indicate if the calling convention is supported +isSupportedCConv :: CCallSpec -> Bool +isSupportedCConv (CCallSpec _ cconv _) = case cconv of + CCallConv -> True -- we explicitly pattern match on every + StdCallConv -> True -- convention to ensure that a warning + PrimCallConv -> False -- is triggered when a new one is added + JavaScriptCallConv -> False + CApiConv -> False + +-- See bug #10462 +unsupportedCConvException :: a +unsupportedCConvException = throwGhcException (ProgramError + ("Error: bytecode compiler can't handle some foreign calling conventions\n"++ + " Workaround: use -fobject-code, or compile this module to .o separately.")) mkSLIDE :: Word16 -> Word -> OrdList BCInstr mkSLIDE n d |