X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FdeSugar%2FDsForeign.lhs;h=51f03c2f8f2c883153f46dbc4813bc9d5a2a97aa;hp=034949fc4519ba8d4720d18721f0f4a35e36c741;hb=3891512c4c770dadd0372ad84d2dec72b34652d2;hpb=569880390c3d9c4d1c5ae748471f37fe5ff8e4db diff --git a/compiler/deSugar/DsForeign.lhs b/compiler/deSugar/DsForeign.lhs index 034949f..51f03c2 100644 --- a/compiler/deSugar/DsForeign.lhs +++ b/compiler/deSugar/DsForeign.lhs @@ -488,6 +488,19 @@ mkFExportCBits c_nm maybe_target arg_htys res_hty is_IO_res_ty cc cResType | res_hty_is_unit = text "void" | otherwise = showStgType res_hty + -- when the return type is integral and word-sized or smaller, it + -- must be assigned as type ffi_arg (#3516). To see what type + -- libffi is expecting here, take a look in its own testsuite, e.g. + -- libffi/testsuite/libffi.call/cls_align_ulonglong.c + ffi_cResType + | is_ffi_arg_type = text "ffi_arg" + | otherwise = cResType + where + res_ty_key = getUnique (getName (typeTyCon res_hty)) + is_ffi_arg_type = res_ty_key `notElem` + [floatTyConKey, doubleTyConKey, + int64TyConKey, word64TyConKey] + -- Now we can cook up the prototype for the exported function. pprCconv = case cc of CCallConv -> empty @@ -571,7 +584,7 @@ mkFExportCBits c_nm maybe_target arg_htys res_hty is_IO_res_ty cc , ptext (sLit "rts_unlock(cap);") , ppUnless res_hty_is_unit $ if libffi - then char '*' <> parens (cResType <> char '*') <> + then char '*' <> parens (ffi_cResType <> char '*') <> ptext (sLit "resp = cret;") else ptext (sLit "return cret;") , rbrace @@ -608,11 +621,12 @@ showStgType :: Type -> SDoc showStgType t = text "Hs" <> text (showFFIType t) showFFIType :: Type -> String -showFFIType t = getOccString (getName tc) - where - tc = case tcSplitTyConApp_maybe (repType t) of - Just (tc,_) -> tc - Nothing -> pprPanic "showFFIType" (ppr t) +showFFIType t = getOccString (getName (typeTyCon t)) + +typeTyCon :: Type -> TyCon +typeTyCon ty = case tcSplitTyConApp_maybe (repType ty) of + Just (tc,_) -> tc + Nothing -> pprPanic "DsForeign.typeTyCon" (ppr ty) insertRetAddr :: CCallConv -> [(SDoc, SDoc, Type, CmmType)] -> [(SDoc, SDoc, Type, CmmType)]