summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <terrorjack@type.dance>2023-02-27 19:11:27 +0000
committerBen Gamari <ben@smart-cactus.org>2023-03-02 10:16:21 -0500
commit8f1ba948e05c123e6d39d703b02979742a986d14 (patch)
tree710c98c4a164f79422433522d73852acfa067cd0
parent0105758bd2596c5147403ec3348b091002e7a92f (diff)
downloadhaskell-8f1ba948e05c123e6d39d703b02979742a986d14.tar.gz
ghc-prim: fix hs_cmpxchg64 function prototype
hs_cmpxchg64 must return a StgWord64, otherwise incorrect runtime results of 64-bit MO_Cmpxchg will appear in 32-bit unregisterised builds, which go unnoticed at compile-time due to C implicit casting in .hc files. (cherry picked from commit 9fa545722f9151781344446dd5501db38cb90dd1)
-rw-r--r--libraries/ghc-prim/cbits/atomic.c4
-rw-r--r--rts/include/stg/Prim.h2
2 files changed, 3 insertions, 3 deletions
diff --git a/libraries/ghc-prim/cbits/atomic.c b/libraries/ghc-prim/cbits/atomic.c
index 2ac6d26e1f..c15c596ddd 100644
--- a/libraries/ghc-prim/cbits/atomic.c
+++ b/libraries/ghc-prim/cbits/atomic.c
@@ -308,8 +308,8 @@ hs_cmpxchg32(StgWord x, StgWord old, StgWord new)
return __sync_val_compare_and_swap((volatile StgWord32 *) x, (StgWord32) old, (StgWord32) new);
}
-extern StgWord hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new);
-StgWord
+extern StgWord64 hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new);
+StgWord64
hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new)
{
return __sync_val_compare_and_swap((volatile StgWord64 *) x, old, new);
diff --git a/rts/include/stg/Prim.h b/rts/include/stg/Prim.h
index 9a04a4eaba..9e5752584a 100644
--- a/rts/include/stg/Prim.h
+++ b/rts/include/stg/Prim.h
@@ -41,7 +41,7 @@ StgWord64 hs_atomic_xor64(StgWord x, StgWord64 val);
StgWord hs_cmpxchg8(StgWord x, StgWord old, StgWord new_);
StgWord hs_cmpxchg16(StgWord x, StgWord old, StgWord new_);
StgWord hs_cmpxchg32(StgWord x, StgWord old, StgWord new_);
-StgWord hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new_);
+StgWord64 hs_cmpxchg64(StgWord x, StgWord64 old, StgWord64 new_);
StgWord hs_atomicread8(StgWord x);
StgWord hs_atomicread16(StgWord x);
StgWord hs_atomicread32(StgWord x);