diff --git a/src/bump.c b/src/bump.c index fcba510d..576f43ae 100644 --- a/src/bump.c +++ b/src/bump.c @@ -39,7 +39,7 @@ align_up(char *ptr, size_t alignment) return ptr + (aligned_addr - addr); } -ATTR_NOINLINE static void * +ATTR_NOINLINE ATTR_MALLOC ATTR_ALLOC_ALIGN(2) static void * bump_aligned_alloc_slow(struct bump *bump, size_t alignment, size_t size) { struct bump_chunk *prev_chunk = bump->current; @@ -65,7 +65,7 @@ bump_aligned_alloc_slow(struct bump *bump, size_t alignment, size_t size) return ptr; } -void * +ATTR_MALLOC ATTR_ALLOC_ALIGN(2) void * bump_aligned_alloc(struct bump *bump, size_t alignment, size_t size) { struct bump_chunk *chunk = bump->current; diff --git a/src/utils.h b/src/utils.h index 57fa9717..e0c70dc3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -336,6 +336,12 @@ open_file(const char *path); #define ATTR_NOINLINE #endif +#if defined(__GNUC__) +#define ATTR_ALLOC_ALIGN(position) __attribute__((alloc_align(position))) +#else +#define ATTR_ALLOC_ALIGN(position) +#endif + #if !(defined(HAVE_ASPRINTF) && HAVE_ASPRINTF) XKB_EXPORT_PRIVATE int asprintf(char **strp, const char *fmt, ...) ATTR_PRINTF(2, 3); # if !(defined(HAVE_VASPRINTF) && HAVE_VASPRINTF)