Add assertions to range-copying primops in debug runtime
In the RTS, some array function have bounds checking assertions (e.g. stg_shrinkSmallMutableArrayzh
), but many, like cloneArray#
, copyArray#
, etc. do not. Consider copyArray#
:
#define copyArray(src, src_off, dst, dst_off, n) \
W_ dst_elems_p, dst_p, src_p, bytes; \
\
if ((n) != 0) { \
SET_HDR(dst, stg_MUT_ARR_PTRS_DIRTY_info, CCCS); \
\
dst_elems_p = (dst) + SIZEOF_StgMutArrPtrs; \
dst_p = dst_elems_p + WDS(dst_off); \
src_p = (src) + SIZEOF_StgMutArrPtrs + WDS(src_off); \
bytes = WDS(n); \
\
prim %memcpy(dst_p, src_p, bytes, SIZEOF_W); \
\
setCards(dst, dst_off, n); \
} \
\
return ();
We could add assertions these at the beginning of the function
ASSERT(StgSmallMutArrPtrs_ptrs(src) >= src_off + n)
ASSERT(StgSmallMutArrPtrs_ptrs(dst) >= dst_off + n)