summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <astrohavoc@gmail.com>2022-03-08 09:41:19 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-03-11 20:00:01 -0500
commit1eee2e28ff51db0b8c2393d68f716c6c7941e779 (patch)
tree246bc3de3da9474102446c99b6c7616bd5d4962d
parent9e67c69e8421f1223a1d14a764740095adeaf89b (diff)
downloadhaskell-1eee2e28ff51db0b8c2393d68f716c6c7941e779.tar.gz
CmmToC: use __builtin versions of memcpyish functions to fix type mismatch
Our memcpyish primop's type signatures doesn't match the C type signatures. It's not a problem for typical archs, since their C ABI permits dropping the result, but it doesn't work for wasm. The previous logic would cast the memcpyish function pointer to an incorrect type and perform an indirect call, which results in a runtime trap on wasm. The most straightforward fix is: don't emit EFF_ for memcpyish functions. Since we don't want to include extra headers in .hc to bring in their prototypes, we can just use the __builtin versions.
-rw-r--r--compiler/GHC/CmmToC.hs9
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs
index 9fe20cc098..a8fa7ef6cb 100644
--- a/compiler/GHC/CmmToC.hs
+++ b/compiler/GHC/CmmToC.hs
@@ -269,7 +269,6 @@ pprStmt platform stmt =
hargs = zip args arg_hints
need_cdecl
- | Just _align <- machOpMemcpyishAlign op = True
| MO_ResumeThread <- op = True
| MO_SuspendThread <- op = True
| otherwise = False
@@ -931,10 +930,10 @@ pprCallishMachOp_for_C mop
MO_F32_Fabs -> text "fabsf"
MO_ReadBarrier -> text "load_load_barrier"
MO_WriteBarrier -> text "write_barrier"
- MO_Memcpy _ -> text "memcpy"
- MO_Memset _ -> text "memset"
- MO_Memmove _ -> text "memmove"
- MO_Memcmp _ -> text "memcmp"
+ MO_Memcpy _ -> text "__builtin_memcpy"
+ MO_Memset _ -> text "__builtin_memset"
+ MO_Memmove _ -> text "__builtin_memmove"
+ MO_Memcmp _ -> text "__builtin_memcmp"
MO_SuspendThread -> text "suspendThread"
MO_ResumeThread -> text "resumeThread"