summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Trangez <ikke@nicolast.be>2022-10-30 22:34:15 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-02 12:06:48 -0400
commit81c0c7c94a58d7ed5634abbb002ef88ef903e218 (patch)
tree03f5cd3070ba261c2fd2fb3c7f5ecb06ee6cc7d9
parent9ab999de7ab22dcb4e32825582203d99ce536f55 (diff)
downloadhaskell-81c0c7c94a58d7ed5634abbb002ef88ef903e218.tar.gz
rts: use `alloc_size` attribute
This patch adds the `STG_ALLOC_SIZE1` and `STG_ALLOC_SIZE2` macros which allow to set the `alloc_size` attribute on functions, when available. See: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
-rw-r--r--rts/RtsUtils.h9
-rw-r--r--rts/include/Stg.h11
2 files changed, 17 insertions, 3 deletions
diff --git a/rts/RtsUtils.h b/rts/RtsUtils.h
index 5282be2035..f2b8bdd1d8 100644
--- a/rts/RtsUtils.h
+++ b/rts/RtsUtils.h
@@ -20,10 +20,12 @@ void shutdownAllocator(void);
void stgFree(void* p);
void *stgMallocBytes(size_t n, char *msg)
- STG_MALLOC STG_MALLOC1(stgFree);
+ STG_MALLOC STG_MALLOC1(stgFree)
+ STG_ALLOC_SIZE1(1);
void *stgReallocBytes(void *p, size_t n, char *msg)
- STG_MALLOC1(stgFree);
+ STG_MALLOC1(stgFree)
+ STG_ALLOC_SIZE1(2);
/* Note: `stgRallocBytes` can *not* be tagged as `STG_MALLOC`
* since its return value *can* alias an existing pointer (i.e.,
* the given pointer `p`).
@@ -32,7 +34,8 @@ void *stgReallocBytes(void *p, size_t n, char *msg)
*/
void *stgCallocBytes(size_t count, size_t size, char *msg)
- STG_MALLOC STG_MALLOC1(stgFree);
+ STG_MALLOC STG_MALLOC1(stgFree)
+ STG_ALLOC_SIZE2(1, 2);
char *stgStrndup(const char *s, size_t n);
diff --git a/rts/include/Stg.h b/rts/include/Stg.h
index 4f1f9d3849..5b5ba3ddb7 100644
--- a/rts/include/Stg.h
+++ b/rts/include/Stg.h
@@ -283,6 +283,17 @@
# define STG_MALLOC2(deallocator, ptrIndex)
#endif
+/*
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute
+ */
+#if stg__has_attribute(__alloc_size__)
+# define STG_ALLOC_SIZE1(position) __attribute__((__alloc_size__(position)))
+# define STG_ALLOC_SIZE2(position1, position2) __attribute__((__alloc_size__(position1, position2)))
+#else
+# define STG_ALLOC_SIZE1(position)
+# define STG_ALLOC_SIZE2(position1, position2)
+#endif
+
/* -----------------------------------------------------------------------------
Global type definitions
-------------------------------------------------------------------------- */